leonucadomi Posted November 21, 2023 Posted November 21, 2023 hello masters: I am using a formula (setq weight ( rtos (/ (atof dato1) 1000) 2 3)) (princ weight) I need it to show three numbers after the decimal point example : 36.560 The problem is that even though I indicated "3" in rtos , truncates me to 36.56 I mean it doesn't show me the last zero Someone knows something about it? thanks Quote
pkenewell Posted November 21, 2023 Posted November 21, 2023 @leonucadomi See this routine on Lee Mac's website: http://www.lee-mac.com/consistentrtos.html 2 Quote
Lee Mac Posted November 21, 2023 Posted November 21, 2023 Essentially, DIMZIN is the reason. 1 1 Quote
fuccaro Posted November 22, 2023 Posted November 22, 2023 This will truncate your string to 3 decimals: (princ (setq weight (/ (fix (* 1000 (atof dato1)))1000.0))) If you wish to round the result, use something like this: (rtos (atof dato1) 2 3) 1 1 Quote
fuccaro Posted November 22, 2023 Posted November 22, 2023 (setq s "123.456789") (setq decs 3) ; desired number of decimals (setq a (substr s 1 (+ 1 decs (vl-string-search "." s)))) If the initial number is already a string, and what you need is also a sting, you can use only string operations, there is no need to convert to number. 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.