leonucadomi Posted November 21, 2023 Share 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 Link to comment Share on other sites More sharing options...
pkenewell Posted November 21, 2023 Share Posted November 21, 2023 @leonucadomi See this routine on Lee Mac's website: http://www.lee-mac.com/consistentrtos.html 2 Quote Link to comment Share on other sites More sharing options...
leonucadomi Posted November 21, 2023 Author Share Posted November 21, 2023 excellent , thanks Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 21, 2023 Share Posted November 21, 2023 Essentially, DIMZIN is the reason. 1 1 Quote Link to comment Share on other sites More sharing options...
fuccaro Posted November 22, 2023 Share 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 Link to comment Share on other sites More sharing options...
fuccaro Posted November 22, 2023 Share 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 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.