Control result of number of decimals

Control result of number of decimals

Anonymous
Not applicable
1,383 Views
6 Replies
Message 1 of 7

Control result of number of decimals

Anonymous
Not applicable
I have this function distance: (distance (getpoint) (getpoint)) The result should leave: 345.5678, with 4 decimals, but only shows me 2. What is the variable that controls the number of decimal places in LISP functions of this type? Thanks for the reply
0 Likes
Accepted solutions (1)
1,384 Views
6 Replies
Replies (6)
Message 2 of 7

Ranjit_Singh
Advisor
Advisor

The result is always stored to full precision but what is displayed is set by your precision of drawing. (getvar 'luprec). The result can be varied by setting luprec to 4. (setvar 'luprec 4) and then calling your distance function. If you do not want to change your drawing units, just convert the result to a string and display to 4 decimals

(read (rtos (distance (getpoint) (getpoint)) 2 4))

 

0 Likes
Message 3 of 7

Anonymous
Not applicable
The same result continues 😞
0 Likes
Message 4 of 7

Ranjit_Singh
Advisor
Advisor

Lets leave out the read what does it say now

(rtos (distance (getpoint) (getpoint)) 2 4)
0 Likes
Message 5 of 7

Anonymous
Not applicable
Now if show me the result with the decimals, but in my program I need it to be numeric and with all the decimals. When I place atof don't shows all the decimals.

What can be happening?
0 Likes
Message 6 of 7

Ranjit_Singh
Advisor
Advisor
Accepted solution

As I said before AutoCAD stores all the precision of data, it just displays it how you code. If you need the numeric version in your program, I would not apply the rtos function. Finish all the processing of data as desired and finally before displaying results convert them to string. Although I honestly have no idea why applying read truncates it to 2 decimals in your system. It does not on mine.

0 Likes
Message 7 of 7

Anonymous
Not applicable
Thank you very much for the suggestions.
0 Likes