Saving real number to string while saving the precision?

Discussion in 'AutoCAD' started by Sage Cowsert, Jan 28, 2004.

  1. Sage Cowsert

    Sage Cowsert Guest

    (setq VALUE 5.0)
    would equal
    (rtos VALUE 2 1)

    (setq VALUE 5.00)
    would equal
    (rtos VALUE 2 2)

    (setq VALUE 5.00568)
    would equal
    (setq VALUE (rtos VALUE 2 5))

    Thoughts?
     
    Sage Cowsert, Jan 28, 2004
    #1
    1. Advertisements

  2. Sage Cowsert

    David Bethel Guest

    Actual decimal values ( .00568 ) precision could be extracted. The .00
    values will be next to impossible. -David
     
    David Bethel, Jan 28, 2004
    #2
    1. Advertisements

  3. Once upon a time I had this issue, and I wrote a routine using (rtos) and
    set the precision to 8 places, more than we ever needed in what we were
    doing. Then, I wrote a simple function to strip off the trailing zeros.
     
    Phil Kenewell, Jan 28, 2004
    #3
  4. Sage Cowsert

    Sage Cowsert Guest

    That might just work 'good enough'. How about something like this? Extra
    trailing Zero's I don't really care about. I just want to make sure that if
    I decide to store a number with this that I'm able to get it back.

    ==============================================
    (defun C:REALTOSTRING (/ REALNUMBER REALSTR CNT)
    (setq REALNUMBER (getreal "\nEnter a number: "))
    (setq REALSTR (rtos REALNUMBER 2 10))
    (setq CNT (strlen REALSTR))
    (while
    (or
    (= "." (substr REALSTR CNT 1))
    (= "0" (substr REALSTR CNT 1))
    )
    (setq CNT (- CNT 1))
    )
    (setq REALSTR (substr REALSTR 1 CNT))
    (prompt (strcat "\nYou specified number: " REALSTR))
    (princ)
    )
     
    Sage Cowsert, Jan 28, 2004
    #4
  5. Looks fine to me! I tried it and it works...
     
    Phil Kenewell, Jan 28, 2004
    #5
  6. ???

    REALTOSTRING
    Enter a number: 1000
    You specified number: 1

    REALTOSTRING
    Enter a number: 10.0
    You specified number: 1

    REALTOSTRING
    Enter a number: 10.00
    You specified number: 1

    --
     
    Marc'Antonio Alessi, Jan 29, 2004
    #6
  7. Sage Cowsert

    Sage Cowsert Guest

    Lets try this...

    (defun C:REALTOSTRING (/ REALNUMBER REALSTR CNT)
    (setq REALNUMBER (getreal "\nEnter a number: "))
    (setq REALSTR (rtos REALNUMBER 2 10))
    (setq CNT (strlen REALSTR))
    (while (= "0" (substr REALSTR CNT 1))
    (setq CNT (- CNT 1))
    )
    (if (= "." (substr REALSTR CNT 1))
    (setq CNT (- CNT 1))
    )
    (setq REALSTR (substr REALSTR 1 CNT))
    (prompt (strcat "\nYou specified number: " REALSTR))
    (princ)
    )
     
    Sage Cowsert, Jan 29, 2004
    #7
  8. REALTOSTRING
    Enter a number: 1000
    You specified number: 1

    REALTOSTRING
    Enter a number: 10.0
    You specified number: 1

    REALTOSTRING
    Enter a number: 10.00
    You specified number: 1

    --
    ________________________________________________

    Marc'Antonio Alessi (TV) Italy
    (strcat "NOT a " (substr (ver) 8 4) " guru.")

    O.S. = XP Pro 2002 Ita - Sp.1
    AutoCAD = 2004 Ita - Sp.1a
    ________________________________________________
     
    Marc'Antonio Alessi, Jan 30, 2004
    #8
  9. Sage Cowsert

    John Uhden Guest

    Sage:

    It can be handled for you by the DIMZIN variable...
    Command: (setvar "dimzin" 8)
    8

    Command: (rtos 12.05 2 10)
    "12.05"

    Command: (rtos 0.05 2 10)
    "0.05"

    Command: (rtos pi 2 10)
    "3.1415926536"
     
    John Uhden, Jan 30, 2004
    #9
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.