How to edit number precision in Applescript??

Discussion in 'Mac Programming' started by crd26, Aug 14, 2006.

  1. macrumors newbie


    Aug 3, 2006
    I have been learning Applescript recently and I can't figure out how to format the precision of a number. I have looked through forums and have looked through a couple of books as well as the Applescript Language Guide.

    The "round" command comes close but isn't exactly what I need.

    What I need in the end it to round numbers to the nearest two decimal places.

    example : 18.094898203 to 18.09

    Thanks for any help!
  2. macrumors 6502a


    Jan 4, 2002
    Austin, TX
    Use this:

    (* format is roundThis(inDec, precision) *)
    roundThis(75.5436, 1) --this will round to 75.5
    on roundThis(n, numDecimals)
       set x to 10 ^ numDecimals
       (((n * x) + 0.5) div 1) / x
    end roundThis
    There is this invention called "Google" that actually lets you search for things you are looking for the answers to your question. Trully amazing, really.
  3. thread starter macrumors newbie


    Aug 3, 2006
    I appreciate your help.

    My looking through Google didn't pay off for me. I'm glad it did for you and thank you for sharing your findings.
  4. macrumors 68000

    Feb 23, 2006
    Can't you just use a double variable?

    Then again, I have not gone that in depth into applescript using numbers, that's where I just fall back to Java.

    EDIT: Applescript doesn't support double types. Not suprised, but it's kind of an expected features, you know?

Share This Page