Jump to content

Recommended Posts

Posted

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

 

 

 

 

 

Posted

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)

 

  • Like 1
  • Thanks 1
Posted
(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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...