Author Topic: ATOF to give all decimal digits from a number as string  (Read 1982 times)

0 Members and 1 Guest are viewing this topic.

DEVITG

  • Bull Frog
  • Posts: 479
ATOF to give all decimal digits from a number as string
« 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 )
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

ronjonp

  • Needs a day job
  • Posts: 7526
Re: ATOF to give all decimal digits from a number as string
« Reply #1 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)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

DEVITG

  • Bull Frog
  • Posts: 479
Re: ATOF to give all decimal digits from a number as string
« Reply #2 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# "")
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

JohnK

  • Administrator
  • Seagull
  • Posts: 10604
Re: ATOF to give all decimal digits from a number as string
« Reply #3 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.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

ronjonp

  • Needs a day job
  • Posts: 7526
Re: ATOF to give all decimal digits from a number as string
« Reply #4 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")))
« Last Edit: April 26, 2021, 11:29:53 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

DEVITG

  • Bull Frog
  • Posts: 479
Re: ATOF to give all decimal digits from a number as string
« Reply #5 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
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

HOSNEYALAA

  • Newt
  • Posts: 103
Re: ATOF to give all decimal digits from a number as string
« Reply #6 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

HOSNEYALAA

  • Newt
  • Posts: 103
Re: ATOF to give all decimal digits from a number as string
« Reply #7 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"

ronjonp

  • Needs a day job
  • Posts: 7526
Re: ATOF to give all decimal digits from a number as string
« Reply #8 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

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

DEVITG

  • Bull Frog
  • Posts: 479
Re: ATOF to give all decimal digits from a number as string
« Reply #9 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



Location @ Córdoba Argentina Using ACAD 2019  at Window 10

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: ATOF to give all decimal digits from a number as string
« Reply #10 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

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: ATOF to give all decimal digits from a number as string
« Reply #11 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), 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")

DEVITG

  • Bull Frog
  • Posts: 479
Re: ATOF to give all decimal digits from a number as string
« Reply #12 on: April 28, 2021, 01:26:41 PM »


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


Location @ Córdoba Argentina Using ACAD 2019  at Window 10