strcat with abs

Discussion in 'AutoCAD' started by amjarch, Sep 21, 2004.

  1. amjarch

    amjarch Guest

    I really hope I am missing something here. Why wont this script run? It refuses the abs value in the strcat and I don't know why. Abs values are just numbers right? This is part of a larger lisp but this part won't work. I have been working on figure this out for too long now. The opn1 and wid2 variables come via user input, then they are rtosed to decimal with a precision to 3 decimal places. Then I use the abs to scrub off the zeros and decimals points. How do I get these abs values to work in a srtcat? Any help will be greatly appreciated.

    (defun c:abs ()
    (setq opn1 36.125
    wid1 6.000
    opn1a (abs opn1)
    wid2a (abs wid1)
    blk (strcat opn1a "-" wid2a)
    )
    (princ opn1a)
    (princ wid2a)
    (princ blk)
    (princ)
    )

    Thanks,
    Drew
     
    amjarch, Sep 21, 2004
    #1
  2. amjarch

    David Bethel Guest

    You need to convert opn1a & wid2a to strings (rtos)

    blk (strcat opn1a "-" wid2a)

    -David
     
    David Bethel, Sep 21, 2004
    #2
  3. amjarch

    amjarch Guest

    The idea is to get strings with only the right amount of information.....6.000 would be lovely as 6 while I still need 36.125 to be 36.125, but if I got 3.500 I would want to see 3.5. I can't rtos to only the important precision can I? Is there a way to query a variable to figure just what precision I need to feed rtos to get what I need?

    my original message was wrong, these variables come straight from getdist and are not rtosed at all.


    Thanks again,
    Drew
     
    amjarch, Sep 21, 2004
    #3
  4. amjarch

    T.Willey Guest

    Try this.

    Tim

    (defun LastSigDigit (RealNum / str1)
    ;| Use (lastsigdigit 16.200000000500000)
    Return "16.2000000005"
    |;

    (setq str1 (rtos RealNum 2 22))
    (while (= (substr str1 (strlen str1) 1) "0")
    (setq str1 (substr str1 1 (1- (strlen str1))))
    )
    str1
    )
     
    T.Willey, Sep 21, 2004
    #4
  5. amjarch

    amjarch Guest

    That will do it!!! Very nice. I will modify it so that once it finishes taking the zeros off it will see if the last item in the string is a "." or not and get rid of it if it is.

    Thanks again,
    Drew
     
    amjarch, Sep 21, 2004
    #5
  6. Clever approach. If you adjust that a little and have it take a character
    off the end as long as it's EITHER "0" or ".", instead of only if it's "0",
    then it would also turn 6.000 into 6 (without the decimal point). Something
    like:

    (setq str1 (rtos RealNum 2 22))
    (while (or (= (substr str1 (strlen str1) 1) ".")
    (= (substr str1 (strlen str1) 1) "0"))
    (setq str1 (substr str1 1 (1- (strlen str1))))
    )
    str1
    )

    Kent Cooper, AIA


    ...
     
    Kent Cooper, AIA, Sep 21, 2004
    #6
  7. Whoops... That would keep taking zeros off if the last character(s) before
    the decimal point were also zero. (In other words, it would also turn
    600.000 or 60.000 into 6.)

    Kent Cooper, AIA


    ...
     
    Kent Cooper, AIA, Sep 21, 2004
    #7
  8. amjarch

    T.Willey Guest

    Here is the finished one. After I ran some test I saw (also) that it left the "." at the end of 6.000.

    Kent,

    That approach wouldn't work, ie. RealNum = 60.00, it would return 6 because of the "0" to the left of the ".". That is what I tried first, but found out it didn't give the disired results. So after it takes away all the "0"s, if the last digit is a ".", it just returns the string without it. Couldn't think of anyother clever way around it.

    Tim

    (defun LastSigDigit (RealNum / str1)
    ;| Use (lastsigdigit 16.200000000500000)
    Return "16.2000000005"
    |;

    (setq str1 (rtos RealNum 2 22))
    (while (= (substr str1 (strlen str1) 1) "0")
    (setq str1 (substr str1 1 (1- (strlen str1))))
    )
    (if (= (substr str1 (strlen str1) 1) ".")
    (setq str1 (substr str1 1 (1- (strlen str1))))
    )
    str1
    )
     
    T.Willey, Sep 21, 2004
    #8
  9. amjarch

    Daron Denton Guest

    (vl-string-right-trim "0" "123.1300000030000")
    "123.130000003"

    (vl-string-right-trim "0" "123.130000000000")
    "123.13"


    --
    Daron
    We are human beings,
    not human doings.



    information.....6.000 would be lovely as 6 while I still need 36.125 to be
    36.125, but if I got 3.500 I would want to see 3.5. I can't rtos to only
    the important precision can I? Is there a way to query a variable to figure
    just what precision I need to feed rtos to get what I need?
     
    Daron Denton, Sep 21, 2004
    #9
  10. amjarch

    T.Willey Guest

    I knew there had to be an easy way. Nice one Daron. After that then just check to see if the last string value is a ".", if so remove it.

    Tim
     
    T.Willey, Sep 21, 2004
    #10
  11. amjarch

    T.Willey Guest

    One problem though.
    Command: (vl-string-right-trim "0" "600")
    "6"

    Command: (lastsigdigit 600)
    "600"

    So I rather use the one I provide with the information you provided. You made it really simple though, thanks Daron.

    Tim

    (defun LastSigDigit (RealNum / str1)
    ;| Use (lastsigdigit 16.200000000500000)
    Return "16.2000000005"
    |;

    (setq str1 (rtos RealNum 2 22))
    (setq str1 (vl-string-right-trim "0" str1))
    (if (= (substr str1 (strlen str1) 1) ".")
    (setq str1 (substr str1 1 (1- (strlen str1))))
    )
    str1
    )
     
    T.Willey, Sep 21, 2004
    #11
  12. (defun ALE_RTOS_DZ8 (real_val / old_dimzin new_val)
    (setq old_dimzin (getvar "DIMZIN"))
    (setvar "DIMZIN" 8)
    (setq new_val (rtos real_val 2))
    (setvar "DIMZIN" old_dimzin)
    new_val
    )


    --

    Marc'Antonio Alessi
    http://xoomer.virgilio.it/alessi
    (strcat "NOT a " (substr (ver) 8 4) " guru.")

    --
     
    Marc'Antonio Alessi, Sep 21, 2004
    #12
  13. amjarch

    T.Willey Guest

    Marc,

    Nice, you taught something new also. Very simple very quick.

    Tim
     
    T.Willey, Sep 21, 2004
    #13
  14. amjarch

    Daron Denton Guest

    or just and "." to "0" :eek:)

    (vl-string-right-trim ".0" "123.1300000030000")
    "123.130000003"

    (vl-string-right-trim ".0" "123.130000000000")
    "123.13"

    (vl-string-right-trim ".0" "123.0000000000")
    "123"

    --
    Daron
    We are human beings,
    not human doings.



    check to see if the last string value is a ".", if so remove it.
     
    Daron Denton, Sep 21, 2004
    #14
  15. amjarch

    Doug Broad Guest

    Trailing zero format is controlled by dimzin. The 8 bit controls
    the display of trailing zeros.

    The number of decimal digits displayed by rtos is determined
    by the third argument to rtos or by the system variable luprec.

    I'm not sure the following would be really practical but it
    demonstrates the behavior.

    (defun NoTrailingZeros (num / olddz return)
    (setq olddz (getvar "dimzin"))
    (setvar "dimzin" 8)
    (setq return (rtos num))
    (setvar "dimzin" olddz)
    return)

    Some of the posts seem to indicate that trailing zeros are
    never significant. That is not true. The accuracy and precision of
    measurements should be known and proper rounding applied.
    Saying a measurement is equal to 2.500 is not the equivalent
    of saying it is equal to 2.5 because a reported value of 2.500
    implies a more precise measurement technique.




    be 36.125, but if I got 3.500 I would want to see 3.5. I can't rtos to only the important precision can I? Is there a way to query
    a variable to figure just what precision I need to feed rtos to get what I need?
     
    Doug Broad, Sep 21, 2004
    #15
  16. amjarch

    Daron Denton Guest

    oops - should read "or just ADD "." to "0"
    :eek:P
     
    Daron Denton, Sep 21, 2004
    #16
  17. amjarch

    Doug Broad Guest

    I see we're on the same wavelength today. ;-)
     
    Doug Broad, Sep 21, 2004
    #17
  18. amjarch

    amjarch Guest

    I just made the one you posted. :) I modified it to accept just a string as I will be doing the rtos stuff prior to the significant digit routine. Also shortened the function name. Copied it into my start up lisp and....it works like a charm.

    Here is the very similar code....if anyone is interested. LSD stand for last significant digit:

    (defun LSD (str1)
    (while (= (substr str1 (strlen str1) 1) "0")
    (setq str1 (substr str1 1 (1- (strlen str1))))
    )
    (if (= (substr str1 (strlen str1) 1) ".")
    (setq str1 (substr str1 1 (1- (strlen str1))))
    )
    str1
    )
     
    amjarch, Sep 21, 2004
    #18
  19. amjarch

    C Witt Guest

    you sound like my math teacher in college..

    oy.. bad..
     
    C Witt, Sep 21, 2004
    #19
  20. amjarch

    Daron Denton Guest

    just curious, isn't this the same result?

    (vl-string-right-trim ".0" "123.130000000000")
    "123.13"

    (vl-string-right-trim ".0" "123.0000000000")
    "123"


    --
    Daron
    We are human beings,
    not human doings.



    as I will be doing the rtos stuff prior to the significant digit routine.
    Also shortened the function name. Copied it into my start up lisp and....it
    works like a charm.
     
    Daron Denton, Sep 21, 2004
    #20
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.