Jump to content

-2 convert to "-2.00"


Dayananda

Recommended Posts

1 hour ago, Isaac26a said:
(setq B (rtos A 2 2))

Even (rtos A 2 2) also = "-2"

Capture1.PNG.37731d3d274c76951796bc2921dd4301.PNG

Edited by Dayananda
Link to comment
Share on other sites

Hello,

 

(defun c:fix()
(setq mysel (ssget '((0 . "TEXT"))))

(setq od (getvar "dimzin"))
(setvar "dimzin" 1)
(setq number 0)
(setq dec (getint "\nnº decimals= "))

(while
	(setq entity1 (ssname mysel number))
	(setq t1 (entget entity1))
	(setq text (cdr (assoc 1 t1)))
	(setq text (vl-string-subst "." "," text))
	(setq num (atof text))
	(setq num (rtos num 2 dec))
	(setq num (vl-string-subst "," "." num))
	(setq par (cons 1 num))
	(setq t1 (subst par (assoc 1 t1) t1))
	(entmod t1)
	(setq number (1+ number))
	)

(setvar "dimzin" od)
)

 

  • Thanks 1
Link to comment
Share on other sites

I've used this modified snippet from ronjonp for many years as I prefer to avoid modifying dimension variables:

  (defun Trim0s (xb) ; Thank ronjonp
	(if (= (type xb) 'real); Trim 0's from end of string conversion, then trim . if it's at the end afterwards.
	  (vl-string-right-trim "." (vl-string-right-trim "0" (vl-princ-to-string xb)))
	  (itoa xb); if integer convert to string without trimming 0's from end.
	)
  )

(trim0s 2.00) returns "2"

(trim0s 2.0300) returns "2.03"

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...