[LISP] How to convert exact string to number?

[LISP] How to convert exact string to number?

iBlachu
Advocate Advocate
1,692 Views
21 Replies
Message 1 of 22

[LISP] How to convert exact string to number?

iBlachu
Advocate
Advocate

I want to exactly convert a number in a string to a number so that it has the same rounding.

 

An example that doesn't work for me.

 

(cvunit 35.5 "KG" "OZ")

1252.23

 

(rtos (cvunit 35.5 "KG" "OZ") 2 3)

"1252.226"

 

Now how do I convert the string from this "1252.226" calculation to a real number?

 

Such action

(atof (rtos (cvunit 35.5 "KG" "OZ") 2 3))

returns 1252.23, not 1252.226!

0 Likes
Accepted solutions (1)
1,693 Views
21 Replies
Replies (21)
Message 21 of 22

kpblc2000
Advisor
Advisor

I tried to say "If you want to see absolutely correct values try to change two system variables : dimzin and luprec. Prehaps it's enough".

Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям! | Do you find the posts helpful? "LIKE" these posts!
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.


Алексей Кулик aka kpblc | Aleksei Kulik aka kpblc Facebook | LinkedIn
autolisp.ru
Техническая поддержка программистов Autodesk в СНГ
Библиотека пользовательских lisp-функций | Custom Lisp-function library

0 Likes
Message 22 of 22

Kent1Cooper
Consultant
Consultant

@iBlachu wrote:

The whole problem boils down to this

(setq a 1252.226)

!a

1252.23


Frustrating as that rounded displayed version is, as in the other topic where you raised this question, it actually "knows" the actual value you gave it, which [for example] it will use in any calculation involving that variable.

 

@kpblc2000, those are not enough -- oddly even with LUPREC set at the maximum value of 8, the displayed precision is increased in the Properties palette, but not in an example like theirs at the command line.

Command: LUPREC

Enter new value for LUPREC <8>: {Enter}

Kent1Cooper_0-1670850447587.png

Command: (setq a 1234.567)
1234.57

Command: !a
1234.57

Kent Cooper, AIA
0 Likes