Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

crd26

macrumors newbie
Original poster
Aug 3, 2006
2
0
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!
 
crd26 said:
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!

Use this:

Code:
(* 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.
 
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.
 
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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.