Re: Round a number towards zero!
Re: Round a number towards zero!
- Subject: Re: Round a number towards zero!
- From: Nigel Garvey <email@hidden>
- Date: Sat, 19 Mar 2005 00:44:29 +0000
Christian Vinaa wrote on Fri, 18 Mar 2005 15:38:07 +0100:
>ok, how do I then fx round to x decimals ?
>(and not to zero )
>where 0,1,2,3,4 gets rounded down and 5,6,7,8,9 gets rounded up
(* Truncate n to d decimal places, with or without rounding. *)
on trnc from n onto d given rounding:rounding
tell 10 ^ d
tell n * ((10 ^ 0.5) ^ 2) * it -- fix for certain awkward floats
if rounding then
it div 5 - it div 10
else
it div 10
end if
end tell
result / it
end tell
end trnc
trnc from 321.245 onto 2 with rounding
--> 321.25
More at:
<http://files.macscripter.net/scriptbuilders/ScriptTools/aRounderRound.sit>
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden