Re: Rounding
Re: Rounding
- Subject: Re: Rounding
- From: Reinhold Penner <email@hidden>
- Date: Tue, 19 Mar 2002 17:48:48 -1000
On Tuesday, March 19, 2002, at 04:50 PM, Paul Berkowitz wrote:
On 3/19/02 5:47 PM, "Rob Jorgensen" <email@hidden> wrote:
Howdy,
I need to extract the minutes from the time string of current date
and then round them up to the next 5 minute increment. I can extract
the minutes with no problem but the rounding is my weak spot (my loss
of mathematical ability is documented in the archives of this list).
:P
So, how do I round 14 to 15, or 16 to 20? Does anyone care to share a
handler which addresses this?
set X to RoundUpTo5(x)
on RoundUpTo5(X)
return (5 * ((x div 5) + 1))
end RoundUpTo5
This won't work for numbers that are already on target (i.e. 5, 10,
15, ...). In order to cover those as well, you need to subtract a value
from x that is smaller than the discreet steps your x values can have.
In this case a value that is smaller than 1. So the script then becomes:
set x to RoundUpTo5(x)
on RoundUpTo5(x)
return (5 * (((x - 0.5) div 5) + 1))
end RoundUpTo5
-Reinhold
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
References: | |
| >Re: Rounding (From: Paul Berkowitz <email@hidden>) |