MojaPana Posted July 20, 2017 Share Posted July 20, 2017 Hello, I have a small problem with decimal places. I have written a small program to write an altitude and draw small figure. Example : when "z" value is 3.0931456... it turns into 3.093 (OK, 3 decimal places) But if "z" value is 2.0000000... it turns into 2 (NOT OK, 0 decimal places), Must be 10.000 Using this command: (setq alti (rtos alta 2 3)) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 20, 2017 Share Posted July 20, 2017 See here: Consistent rtos Quote Link to comment Share on other sites More sharing options...
Aftertouch Posted July 20, 2017 Share Posted July 20, 2017 when Z = a string: (setq alti "2.00000000") <= given value (setq alti (strcat (substr alti 1 (vl-string-position (ascii ".") alti)) (substr alti (+ (vl-string-position (ascii ".") alti) 1) 4))) returns: "2.000" when Z = a real: (setq alti 2.00000000) <= given value (setq alti (rtos alti))(setq alti (strcat (substr alti 1 (vl-string-position (ascii ".") alti)) (substr alti (+ (vl-string-position (ascii ".") alti) 1) 4))) returns: "2.000" Quote Link to comment Share on other sites More sharing options...
ziele_o2k Posted July 20, 2017 Share Posted July 20, 2017 ; =========================================================================================== ; ; Konwertuje liczbe na lancuch tekstowy / Converts number to a string ; ; Val [REAL/INT] - liczba do konwersji / conversion number ; ; Unit [iNT/nil] - jednostki wyjsciowe / output unit ; ; nil = domyslne / default | (getvar "LUNITS") ; ; 1 = naukowe / scientific ; ; 2 = dziesietne / decimal ; ; 3 = inzynierskie / engineering ; ; 4 = architektoniczne / architectural ; ; 5 = ulamkowe / fractional ; ; Prec [iNT/nil] - INT = liczba miejsc po przecinku / number of decimal places ; ; nil = domyslna / default | (getvar "LUPREC") ; ; ------------------------------------------------------------------------------------------- ; ; (cd:CON_Real2Str 12 2 4) ; ; =========================================================================================== ; (defun cd:CON_Real2Str (Val Unit Prec / DMZ res) (setq DMZ (getvar "DIMZIN")) (setvar "DIMZIN" (if (not (member (getvar "LUNITS") (list 4 5))) (logand DMZ (~ ) 0 ) ) (setq res (rtos Val (if (and Unit (member Unit (list 1 2 3 4 5))) Unit (getvar "LUNITS") ) (if Prec Prec (getvar "LUPREC")) ) ) (setvar "DIMZIN" DMZ) res ) From: CADPL-Pack-v1.lsp Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.