Re: How can I round in applescript to 3 digits after a period?
Re: How can I round in applescript to 3 digits after a period?
- Subject: Re: How can I round in applescript to 3 digits after a period?
- From: "Mark J. Reed" <email@hidden>
- Date: Thu, 3 Jan 2008 12:57:03 -0500
I.e. 19.9898923978923892 should just be rounded to 19.989
That's not rounding, that's truncating. 19.9898 rounds to 19.990.
Also 19.0909 should just be rounded to 19.989
You mean 19.091?
Per what I understand rounding in applescript rounds to an integer so is there
a different rounding method that I can use to round to three digits after the
period?
The usual method to get more precision is to multiply by a power of 10 so that all the digits you want to keep are to the left of the decimal, then convert to an integer, and then divide by that power of 10 again. For example:
set origNum to 19.989892397892
set roundedNum to ((origNum * 1000) as integer) / 1000.0
-- 19.99
--
Mark J. Reed <
email@hidden
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden