remove numbers after the decimal

Discussion in 'AutoCAD' started by Joe Smetanko, Aug 10, 2004.

  1. Joe Smetanko

    Joe Smetanko Guest

    Does anyone have anything that will remove the numbers after the decimal
    point?

    Example
    I have thousands of text contain numbers to the 100th decimal place (
    150.00, 210.00 etc...)
    I need to just delete the decimal and all text after that ( 150 , 210 )

    Thanks

    --
    Windows 2000 SP4
    LDD 2004 SP2

    Joe Smetanko
    R.D. Zande & Associates, Inc.
    1500 Lake Shore Drive
    Columbus, Ohio 43204
     
    Joe Smetanko, Aug 10, 2004
    #1
  2. DIMZIN?

    Controls the suppression of zeros in the primary unit value. DIMZIN stores this value when you enter
    it on the command line or set it under Primary Units in the Annotation dialog box. DIMZIN values 0-3
    affect feet-and-inch dimensions only.


    0 Suppresses zero feet and precisely zero inches

    1 Includes zero feet and precisely zero inches

    2 Includes zero feet and suppresses zero inches

    3 Includes zero inches and suppresses zero feet

    4 Suppresses leading zeros in decimal dimensions (for example, 0.5000 becomes .5000)

    8 Suppresses trailing zeros in decimal dimensions (for example, 12.5000 becomes 12.5)

    12 Suppresses both leading and trailing zeros (for example, 0.5000 becomes .5)


    DIMZIN also affects real-to-string conversions performed by the AutoLISP rtos and angtos functions.
     
    Allen Johnson, Aug 10, 2004
    #2
  3. If not DIMZIN, try

    (rtos (distof txt) 2 0)
     
    Allen Johnson, Aug 10, 2004
    #3
  4. Joe Smetanko

    Joe Smetanko Guest

    these are in decimal format

    --
    Windows 2000 SP4
    LDD 2004 SP2

    Joe Smetanko
    R.D. Zande & Associates, Inc.
    1500 Lake Shore Drive
    Columbus, Ohio 43204
     
    Joe Smetanko, Aug 10, 2004
    #4
  5. Joe Smetanko

    Joe Smetanko Guest

    Also - this is plain DTEXT not dimensions


    --
    Windows 2000 SP4
    LDD 2004 SP2

    Joe Smetanko
    R.D. Zande & Associates, Inc.
    1500 Lake Shore Drive
    Columbus, Ohio 43204
     
    Joe Smetanko, Aug 10, 2004
    #5
  6. Does it have anything but dimensional text? If not then the (rtos (distof txt) 2 0) should work:

    Command: (setq txt "100.20")
    "100.20"

    Command: (rtos (distof txt) 2 0)
    "100"
     
    Allen Johnson, Aug 10, 2004
    #6
  7. Try this, see if it works for you. Should be ok if it's all dtext.

    ;;rounds off an elevation to the nearest tenth
    ;;and deletes the old one
    (defun c:ro ()
    (setq el(entget(car(entsel "\nPick Elevation:"))))
    (setq el1(assoc 1 el))
    (setq el2(cdr el1))
    (setq el3(rtos(atof el2)2 1))
    (setq sz(assoc 40 el))
    (setq sz1(cdr sz))
    (setq ang(angtos(cdr(assoc 50 el))))
    (setq ins(cdr(assoc 10 el)))
    (command "_text" ins sz1 ang el3)
    (setq dl(assoc -1 el))
    (setq dl1(cdr dl))
    (entdel dl1)
    (prompt "Elevation Rounded")
    (princ)
    )
     
    John Michalik, Aug 10, 2004
    #7
  8. Joe Smetanko

    T.Willey Guest

    Allen,

    I just tried that and it rounded my numbers off. Example I had a text value of "4.89" after I tried your idea it returned "5".

    Command: (rtos (distof "4.9") 2 0)
    "5"

    Tim
     
    T.Willey, Aug 10, 2004
    #8
  9. Dang Joe, just realized that you are trying to remove ALL numbers after the
    decimal, not just round off. Sorry, if someone here is better with LISP,
    maybe they can modify the code I posted.

    --
    John Michalik
    Drafting and Design
    LDD/CAD Development & Standards

    value of "4.89" after I tried your idea it returned "5".
     
    John Michalik, Aug 10, 2004
    #9
  10. Try this:

    (defun C:RO (/ pickObj myObj txt)
    (vl-load-com)
    (setq pickObj (entsel))
    (setq myObj (vlax-EName->vla-Object (car pickObj)))
    (if (= (vla-Get-ObjectName myObj) "AcDbText")
    (progn
    (setq txt (vla-get-textstring myobj)
    txt (rtos (distof txt) 2 0))
    (vla-put-textstring myobj txt )
    )
    )
    )
     
    Allen Johnson, Aug 10, 2004
    #10
  11. Try the "atoi" lisp function. It cuts off decimals without rounding up.

    Kent Cooper, AIA


    value of "4.89" after I tried your idea it returned "5".
     
    Kent Cooper, AIA, Aug 10, 2004
    #11
  12. Allen that works great. Actually, it brought to light another problem when
    I tried it against my old one. The original lisp I posted was written for
    R14 and I honestly haven't had a need for it since the labeling routines
    with LDD allow me to bring in the elevation as I wish it to be, but when I
    tried to use mine on an elevation, it went crazy, rotated the text, changed
    from an elevation to deg/min/sec and some other things. I think maybe
    because it was originally written to work with C&G text which may use a
    different formatting.

    txt (rtos (distof txt) 2 0))

    If I change the 2 to a 1 in the string above (from your code), would that be
    what it takes for it to round to the tenth? I must admit, I'm not very good
    with lisp and the one I posted was written by a tech that used to work here
    long ago. I generally relegate myself to watching and learning in this
    group. Just thought for a second here I might be able to help on this
    one!!!
     
    John Michalik, Aug 10, 2004
    #12
  13. The third field in the rtos function designates the number of decimal places, so changing the zero
    to one will round to one decimal place. The second field (2) indicates the type of units:
    1 Scientific
    2 Decimal
    3 Engineering (feet and decimal inches)
    4 Architectural (feet and fractional inches)
    5 Fractional
     
    Allen Johnson, Aug 10, 2004
    #13
  14. Joe Smetanko

    T.Willey Guest

    Kent that worked. Here is the lisp

    (defun C:REMDEC (/ tset cnt1 ent1 oldval newval dcpl slng)

    (command "_.undo" "_end")
    (command "_.undo" "_group")
    (prompt "\nSelect text objects: ")
    (setq tset (ssget '((0 . "TEXT")))
    cnt1 0
    )
    (if tset
    (progn
    (setq slng (sslength tset))
    (while (/= slng cnt1)
    (setq ent1 (entget (ssname tset cnt1))
    oldval (cdr (assoc 1 ent1))
    newval (rtos (atoi oldval) 2 0)
    ent1 (subst (cons 1 newval) (assoc 1 ent1) ent1)
    cnt1 (1+ cnt1)
    )
    (entmod ent1)
    )
    )
    (prompt "\n No text objects selected. ")
    )
    (command "_.undo" "_end")
    (princ)
    )

    Tim
     
    T.Willey, Aug 10, 2004
    #14
  15. Another method that can be used for other applications -
    (setq NUM "1234.567")
    (setq NewNum (car (GETTEXTLIST NUM ".")))
    returns "1234"

    ; subroutine to create list from text be separation character(s)
    (defun GETTEXTLIST (TTT TF / LTF KKS KKF KKK KKL)
    (setq LIST_TEXT nil)
    (setq LTF (strlen TF))
    (setq KKS 1 KKF 0 KKK 1 KKL (strlen TTT))
    (while (<= KKK KKL)
    (if (= (substr TTT KKK LTF) TF)
    (progn
    (setq LIST_TEXT (append LIST_TEXT (list (substr TTT KKS (- KKK
    KKS)))))
    (setq KKS (+ KKK LTF))
    )
    )
    (setq KKK (1+ KKK))
    )
    (setq LIST_TEXT (append LIST_TEXT (list (substr TTT KKS))))
    )
     
    Alan Henderson @ A'cad Solutions, Aug 10, 2004
    #15
  16. ahhhh....I get it. Great. Thanks Allen!
     
    John Michalik, Aug 10, 2004
    #16
  17. Joe Smetanko

    PG. Guest

    (itoa (atoi (rtos 1234.567)))
    returns
    "1234" as a string without rounding the number.
     
    PG., Aug 10, 2004
    #17
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.