Isn't there a more simple way?

Discussion in 'AutoCAD' started by Marcel Janmaat, Apr 14, 2004.

  1. Hello there,

    I have this tiny question;

    dst = 5400.0
    (fix dst) = 5399

    how do i make from dst 5400?

    now i use (atoi (rtos dst 2 0))

    So far I haven't seen a "rtoi" function

    MJ
     
    Marcel Janmaat, Apr 14, 2004
    #1
  2. Marcel Janmaat

    CAB2k Guest

    (fix (+ dst 0.999999))
     
    CAB2k, Apr 14, 2004
    #2
  3. Marcel Janmaat

    bob.at Guest

    CAB,
    better is the following:
    (fix (+ dst 0.0001))

    Marcel
    I've tried it in AutoCAD 2004 but cannot reproduce the problem, but i dont know from where you get the number for dist. Evitetntly Lisp operates with 16 significant signs:
    (fix 5399.999999999999) -> 5399 (12 "9"s behind dec point)
    (fix 5399.9999999999999) -> 5400 (13 "9"s behind dec point)

    bob.at
     
    bob.at, Apr 14, 2004
    #3
  4. That is the power of AutoLISP, VBA, etc.
    The ability to write your own functions.

    I would go with your current method (atoi (rtos NUM 2 0))
    (rtos ## 2 0) should round numbers from 0.5 to 1.49999+ to 1

    (defun RTOI (NN /) (atoi (rtos NN 2 0))

    This is a typical error in programming, where the display rounds up.
    (setq NUM 1.99999) = displays 1.99999
    (setq NUM 1.999999) = displays 2.0 (Note - this does NOT mean that the
    value is 2.0)

    Another example of error in programming is the number of significant decimal
    places
    (atoi (rtos 1.499999999999999 2 0)) 2
    (atoi (rtos 1.49999999999999 2 0)) 1
     
    Alan Henderson, Apr 14, 2004
    #4
  5. Thanx Bob;

    I know of the 9digit situation. I always soved it the way I described (with
    rtos and atoi).
    But thought it's strange there's no simple built-in function for it.

    I thought, if there's an "rtos", why not also an "rtoi". But it seems not,
    from your reply.

    Thanx again!

    know from where you get the number for dist. Evitetntly Lisp operates with
    16 significant signs:
     
    Marcel Janmaat, Apr 14, 2004
    #5
  6. Marcel Janmaat

    bob.at Guest

    If you realy want to round the number, then you can use (fix (+ dst 0.5))
     
    bob.at, Apr 14, 2004
    #6
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.