Jéferson Gustavo Posted September 19, 2020 Posted September 19, 2020 Hello everyone. I need your help again. Let's suppose that I have the real number 10000.34252 and I need to transform it into the following string "10.000,343" that is, add the "." to separate thousands, and leave it to 3 decimal places. The rtos even helps to leave with 3 decimal places, however when it comes to numbers with less than 3 decimal places, it does not add the leading zero. For example, when we apply (rtos 3.1000 2 3), it returns "3.1", when I wanted "3,100") I even created a solution, but I would like to know if there is a cleaner way to do this. Here is my solution: (setq number_str 10000.34252) (setq number_str (rtos number_str 2 3) number_str (vl-string-subst "," "." number_str )) (cond ((= number_str "0")) ((= (vl-string-search "," number_str) nil)(setq number_str (strcat number_str ",000"))) ((= (- (strlen number_str) (vl-string-search "," number_str) 1) 1)(setq number_str (strcat number_str "00"))) ((= (- (strlen number_str) (vl-string-search "," number_str) 1) 2)(setq number_str (strcat number_str "0")))) (if (> (vl-string-search "," number_str) 3) (setq number_str (strcat (substr number_str 1 (- (vl-string-search "," number_str) 3)) "." (substr number_str (- (vl-string-search "," number_str) 2))))) This returns "10.000,343". Thank you in advance Quote
Tharwat Posted September 19, 2020 Posted September 19, 2020 Set the system variable DIMZIN to zero before running the rots function then set it back to its default. 1 Quote
dlanorh Posted September 19, 2020 Posted September 19, 2020 If your drawing is metric, try setting the system variable "DIMZIN" to 0 (zero) . Settings 0->3 only affect feet and inches and in 2012 this doesn't suppress trailing zero's in metric drawings. You can test on the command line with (rtos num 2 3) 1 Quote
Jéferson Gustavo Posted September 22, 2020 Author Posted September 22, 2020 Thank you very much! Quote
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.