TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: DEVITG on April 26, 2021, 05:15:55 PM

Title: ATOF to give all decimal digits from a number as string
Post by: DEVITG on April 26, 2021, 05:15:55 PM
Hi all . please clear me : how to get all decimal from a number as string.

I remember some about DIMZIN LUPREC but I can't get it

I work acad 2019  units millimeters 
 

Code: [Select]
(atof "27.1600748145263")
to be
 (setq value   27.1600748145263 )
Title: Re: ATOF to give all decimal digits from a number as string
Post by: ronjonp on April 26, 2021, 05:47:25 PM
See if this sheds any light:
Code - Auto/Visual Lisp: [Select]
  1. (setq val (atof "27.1600748145263"))
  2. (rtos val 2 16)
Title: Re: ATOF to give all decimal digits from a number as string
Post by: DEVITG on April 26, 2021, 06:48:35 PM
Hi @ronjonp , I need the string to be  a real , I got it from a CSV file , and need it to supply to  point command.


Code: [Select]
  (setq pt1$  '("291235.933" "288772.8917" "27.49299344"))
to be

 
Code: [Select]
(setq pt1#   '(291235.933 288772.8917 27.49299344))
 
Code: [Select]
(command "_point" pt1# "")
Title: Re: ATOF to give all decimal digits from a number as string
Post by: JohnK on April 26, 2021, 07:13:34 PM
This topic is in the incorrect forum. I will be moving it to the AutoLisp general forum.
Title: Re: ATOF to give all decimal digits from a number as string
Post by: ronjonp on April 26, 2021, 10:44:25 PM
Hi @ronjonp , I need the string to be  a real , I got it from a CSV file , and need it to supply to  point command.


Code: [Select]
  (setq pt1$  '("291235.933" "288772.8917" "27.49299344"))
to be

 
Code: [Select]
(setq pt1#   '(291235.933 288772.8917 27.49299344))
 
Code: [Select]
(command "_point" pt1# "")
Try this:
Code - Auto/Visual Lisp: [Select]
  1. (setq pt (mapcar 'atof '("291235.933" "288772.8917" "27.49299344")))
Title: Re: ATOF to give all decimal digits from a number as string
Post by: DEVITG on April 27, 2021, 09:04:00 AM
Hi Ronjonp.

which system variable control the decimal digits to be show?

        I need all value to be as the original text

See file attached
Title: Re: ATOF to give all decimal digits from a number as string
Post by: HOSNEYALAA on April 27, 2021, 10:17:58 AM
It looks like trailing zeroes are being suppressed. Perhaps examination of the system variable DIMZIN would have avoided your troubles in the first place.

https://www.cadtutor.net/forum/topic/71145-if-possible-help-inserting-two-numbers-after-the-comma/?tab=comments#comment-5709719
Title: Re: ATOF to give all decimal digits from a number as string
Post by: HOSNEYALAA on April 27, 2021, 10:19:41 AM
Eldon solution maybe easiest

(setq x 20.1)
20.1
: DIMZIN
New current value for DIMZIN (0 to 15) <8>:0
: (rtos x 2 2)
"20.10"
: (setq x 20)
20
: (rtos x 2 2)
"20.00"
Title: Re: ATOF to give all decimal digits from a number as string
Post by: ronjonp on April 27, 2021, 02:24:50 PM
Hi Ronjonp.

which system variable control the decimal digits to be show?

        I need all value to be as the original text

See file attached

Use this: http://www.lee-mac.com/consistentrtos.html
Title: Re: ATOF to give all decimal digits from a number as string
Post by: DEVITG on April 27, 2021, 05:13:51 PM
Hi Ronjonp.

I do not need to get a string from a number like the return from  RTOS

see screen shot from LEE site , as attached

I need to get a  REAL from a STRING with all the decimal to be the same as at the string

Code: [Select]
(setvar 'dimzin 15)
(setq string-list (list "291236.8554589" "288773.10512548" "27.8163568"))
 (setq real-list (mapcar 'atof string-list))


it return

Code: [Select]
("291236.8554589" "288773.10512548" "27.8163568")
(291237.0 288773.0 27.8164)
 

or from
Code: [Select]
(setq string (car string-list))
(setq real (atof string))

it return

Code: [Select]
"291236.8554589"
291237.0



Title: Re: ATOF to give all decimal digits from a number as string
Post by: VovKa on April 27, 2021, 05:47:05 PM
it return

Code: [Select]
"291236.8554589"
291237.0
wrong
it does not return 291237.0
it only prints out 291237.0

yes, vlide rounds reals when showing them in the console or inspect windows
Title: Re: ATOF to give all decimal digits from a number as string
Post by: Lee Mac on April 27, 2021, 05:48:50 PM
The real values returned by the atof function are still being stored using the maximum precision afforded by the double-precision floating-point format (as discussed in another recent thread (https://www.theswamp.org/index.php?topic=56694.msg604372#msg604372)), the values are merely truncated/rounded when output to the VLIDE console or AutoCAD command line - observe:
Code - Auto/Visual Lisp: [Select]
  1. _$ (setq string-list (list "291236.8554589" "288773.10512548" "27.8163568"))
  2. ("291236.8554589" "288773.10512548" "27.8163568")
  3. _$ (setq real-list (mapcar 'atof string-list))
  4. (291237.0 288773.0 27.8164)
  5. _$ (mapcar '(lambda ( x ) (rtos x 2 15)) real-list)
  6. ("291236.8554589000" "288773.1051254800" "27.81635680000000")
Title: Re: ATOF to give all decimal digits from a number as string
Post by: DEVITG on April 28, 2021, 01:26:41 PM


Thanks all you. Now I got it . Cost but it worth .