I just received an email from an Engineer from Japan telling me that my rtosr function is not working correctly in AutoCAD 2008. It was first written in AutoCAD R14 as a replacement for the rtos function for converting numbers without specifying the precision, and its accurate up to 8 decimal places. We only have AutoCAD 2004 thru 2006 here at work, and it works just like it was intended to. One of the Engineers has AutoCAD 2007 on his lap top at home and came across this change in the AutoLISP function rtos. The rtos function truncates the leading 0 in numbers less than 0, where as in previous versions it left the 0. In AutoCAD 2006 (rtos 0.12345678 2 8 ) = 0.12345678. In AutoCAD 2007 (rtos 0.12345678 2 8 ) = .12345678.
If you have AutoCAD 2008 can you test the revised function for me?
Here are a few of the examples and the returns you should see:
(rtosr 0.000000004) = "0"
(rtosr 0.000000005) = "0.00000001"
(rtosr 1.01562500) = "1.015625"
(rtosr 2.031250) = "2.03125"
(rtosr 3.062500) = "3.0625"
(rtosr 4.125000) = "4.125"
In the following revision the leading 0 is added back in if it was truncated.
;-------------------------------------------------------------------------------
; rtosr - Used to change a real number into a short real number string
; stripping off all trailing 0's.
; Arguments: 1
; RealNum~ = Real number to convert to a short string real number
; Returns: ShortReal$ the short string real number value of the real number.
;-------------------------------------------------------------------------------
(defun rtosr (RealNum~ / Loop ShortReal$)
(setq ShortReal$ (rtos RealNum~ 2 8))
(if (= (substr ShortReal$ 1 1) ".")
(setq ShortReal$ (strcat "0" ShortReal$))
);if
(setq Loop t)
(while Loop
(if (= (substr ShortReal$ (strlen ShortReal$) 1) "0")
(setq ShortReal$ (substr ShortReal$ 1 (1- (strlen ShortReal$))))
(setq Loop nil)
);if
);while
(if (= (substr ShortReal$ (strlen ShortReal$) 1) ".")
(setq ShortReal$ (substr ShortReal$ 1 (1- (strlen ShortReal$))))
);if
(if (= ShortReal$ "")
(setq ShortReal$ "0")
);if
ShortReal$
);defun rtosr
This function was used in my GetExcel.lsp and DrawExcel.lsp functions.