Re: Coercing Numbers
Re: Coercing Numbers
- Subject: Re: Coercing Numbers
- From: "Stockly, Ed" <email@hidden>
- Date: Fri, 26 Feb 2010 12:44:40 -0800
- Thread-topic: Coercing Numbers
Title: Re: Coercing Numbers
set x to 124.956 * 100 as integer
The correct answer is 12495.6, but the script returns 12396.
In that case this might be a better solution:
set x to round (124.95 * 100)
Because it gives you those nifty options:
set x to round (124.955 * 100)
set x to round (124.955 * 100) rounding up
set x to round (124.955 * 100) rounding down
set x to round (124.955 * 100) rounding toward zero
set x to round (124.955 * 100) rounding as taught in school
set x to round (124.955 * 100) rounding to nearest --the default
Rounding direction, if omitted, rounds to nearest.
“to nearest” rounds .5 cases to the nearest even integer in order to decrease cumulative errors.
To always round .5 away from zero, use “as taught in school.”
HTH,
ES
_______________________________________________
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