Can someone quickly explain why "rtos" rounds and minuses potential string characters?

Can someone quickly explain why "rtos" rounds and minuses potential string characters?

3rduser
Contributor Contributor
1,303 Views
5 Replies
Message 1 of 6

Can someone quickly explain why "rtos" rounds and minuses potential string characters?

3rduser
Contributor
Contributor

Working on a simple calculation lisp here and I ran into an issue I don't understand. I was always under the impression that "rtos" took a real number exactly for what it was and made it into a string, apparently it does not. How come if I take the following code:

 

(defun c:test\ ( / upstr dwnstr dist calc )
	(setq upstr 390.17)
	(setq dwnstr 380.17)
	(setq dist 112.73)
	(setq calc (/ (- upstr dwnstr) dist))
	(princ calc)
	(princ)
)

 I get 0.0887075 but if I add the following rtos function:

 

(defun c:test\ ( / upstr dwnstr dist calc )
	(setq upstr 390.17)
	(setq dwnstr 380.17)
	(setq dist 112.73)
	(setq calc (rtos (/ (- upstr dwnstr) dist)))
	(princ calc)
	(princ)
)

 my new result is .0887

 

how come rtos gets rid of my initial "0" and whatever is after the 4th character? where is the "075" at the end? why isn't it a literal translation? what if I need to work with the entire real  number result as a string how would I truly get it?

 

Any insight is appreciated.

0 Likes
1,304 Views
5 Replies
Replies (5)
Message 2 of 6

ronjonp
Mentor
Mentor

@3rduser

Have a read HERE.

Message 3 of 6

Kent1Cooper
Consultant
Consultant

Read about (rtos) in the AutoLisp Reference [always the first place to look].  It will tell you, for example, that you get to specify how many decimal places it includes.  If you don't specify, it will use whatever your current Units precision setting is.  Interestingly, that is limited to 8 decimal places, but you can take the precision a lot further in (rtos) [within AutoCAD's number-handling limitation to "only" 16 significant figures].

 

[EDIT:  But consider also whether a precision down to less than a 10,000th of whatever your drawing unit represents is actually meaningful at all.]

 

The DIMZIN System Variable setting determines whether leading and/or trailing zeroes are suppressed.

Kent Cooper, AIA
Message 4 of 6

3rduser
Contributor
Contributor

@ronjonp 

@Kent1Cooper 

 

thank you for the insights! much appreciated.

0 Likes
Message 5 of 6

ronjonp
Mentor
Mentor

@3rduser Glad to help.  Look into vl-princ-to-string.  It does not have the dimzin limit.

(defun c:test\ (/ upstr dwnstr dist calc)
  (setq upstr 390.17)
  (setq dwnstr 380.17)
  (setq dist 112.73)
  (setq calc (vl-princ-to-string (/ (- upstr dwnstr) dist)))
  (princ calc)
  (princ)
)
;; Command: TEST\
;; 0.0887075
0 Likes
Message 6 of 6

john.uhden
Mentor
Mentor

Thanks, @ronjonp .  I didn't know that.

My only problem is that the symbol names imply to me some kind of water or sewage conduit.  Normally we civils treat conduit slopes as from upstream to downstream, in which case one would subtract the higher number from the lower number and end up with a negative slope value, meaning the fluid is flowing downhill, as it should be if the only force is gravity.  Then again, performing pipe capacity calculations we treat all slopes as positive, lest we like imaginary numbers (or whatever they're called) trying to calculate the square root of a negative slope. 😕

John F. Uhden

0 Likes