atof rounds large number lisp

atof rounds large number lisp

divymital
Enthusiast Enthusiast
1,502 Views
7 Replies
Message 1 of 8

atof rounds large number lisp

divymital
Enthusiast
Enthusiast

Hi,

 

I have a scenario where I am using X,Y,Z from a csv file and create points form the data and use it further in my lisp.

 

When I use atof to get the coordinates it rounds of the decimal value and hence point prepared is incorrect and not on the line (form where it was extracted into the csv) Due to this code fails.

 

Ex for X Coordinate : (setq X (atof "494965.6096")) returns 494966.0. I need 494965.6096 in response. As I dont get decimal points exact point is not re-created. Is there any way that I can get 494965.6096 in variable from "494965.6096". 

 

Please suggest. I have gone through various posts but could not find a solution. Please help.

 

Regards,
Divya

0 Likes
Accepted solutions (1)
1,503 Views
7 Replies
Replies (7)
Message 2 of 8

CodeDing
Advisor
Advisor

@divymital ,

 

AutoCAD does not lose or forget the precision of your items unless told to do so.

Storing your variable as you are will return on the command line as follows:

Command: (setq x (atof "494965.6096"))
494966.0

But this does not mean that our variable was rounded. We can verify this with the following:

Command: (setq x (atof "494965.6096"))
494966.0
Command: (rtos x 2 4)
"494965.6096"

...you are storing your variable correctly.

Best,

~DD

0 Likes
Message 3 of 8

divymital
Enthusiast
Enthusiast

Hi,

 

Thanks for the response , In my scenario I am reading a csv file having X,Y,Z and few other information (Please find attached for your reference). I get the comma separated string and I further split it by comma to get individual string.

 

Ex from the attached file (1st line) : "CS-1/NALA,494965.6096,2305782.191,0,205.2849 ". Now I need to make point (494965.6096 2305782.191 0.0) which is coming out to be rounded (494966 2305782 0.0) as incorrect point. Is there a way that I can get the expected point here.

 

 

Regards,

Divya

0 Likes
Message 4 of 8

divymital
Enthusiast
Enthusiast

Missed to upload file in my reply . PFA the same.

0 Likes
Message 5 of 8

CodeDing
Advisor
Advisor

@divymital ,

 

"is coming out to be rounded (494966 2305782 0.0) as incorrect point"

 

How are you determining this? Are you looking at properties box? Using (princ ...)?

 

Try changing your precision units and checking again...

(progn (setvar 'LUPREC 4) (setvar 'AUPREC 4))
0 Likes
Message 6 of 8

divymital
Enthusiast
Enthusiast

I checked this by inspect option. PFA the image with the inspect data of the re-created point (left) and the csv row data (right).

 

I have run the suggested command also, but it gives the same thing.

0 Likes
Message 7 of 8

CodeDing
Advisor
Advisor
Accepted solution

I am not sure why Inspector would return that exactly. But your variable is still storing the correct point. Seems like more of an "Inspect" issue than an AutoCAD issue...

image.png

0 Likes
Message 8 of 8

divymital
Enthusiast
Enthusiast

Thanks for the suggestion , Point is coming on the same point 🙂

0 Likes