Re: Round Handler, care to share.
Re: Round Handler, care to share.
- Subject: Re: Round Handler, care to share.
- From: Nigel Garvey <email@hidden>
- Date: Thu, 7 Dec 2000 00:07:21 +0000
"Bourque, Jason" wrote on Wed, 6 Dec 2000 15:35:23 -0500:
>
Hello,
>
>
Does anyone have a vanilla handler that finds the next rounded value of a
>
number, this is to be used in charts.
>
>
i.e. 17.2 rounded would be 20
>
>
22.8 rounded would be 25
It looks as though you want to round *away from zero* to the next
multiple of 5. If so, this is very fast:
on rndAwayTo5(n) -- away from zero
tell n div 5 * 5
if it < n then return it + 5
if it > n then return it - 5
it
end tell
end rndAwayTo5
If, on the other hand, you want the *nearest* multiple of 5 (2.5 rounding
away from zero):
on rndTo5(n) -- to nearest 5
tell n / 5
(it div 0.5 - it div 1) * 5
end tell
end rndTo5
NG