Re: Round a number towards zero!
Re: Round a number towards zero!
- Subject: Re: Round a number towards zero!
- From: Jeff Shapiro <email@hidden>
- Date: Fri, 18 Mar 2005 08:52:11 -0700
- Organization: Nensha
Christian Vinaa was seen on 3/18/05 3:38 PM talking about:
> ok, how do I then fx round to x decimals ?
> (and not to zero )
>
> ex:
>
> US style 1,000.1234 --> 1,000.12
>
> Euro style 1.000,1234 --> 1.000,12
>
> where 0,1,2,3,4 gets rounded down and 5,6,7,8,9 gets rounded up
Here's a handler that will let you specify the number of digits to
round:
(watch for line wrops)
on myRound(num, numDigits)
return (round num * (10 ^ numDigits) rounding as taught in school) /
(10 ^ numDigits)
end myRound
if numDigits is > 0, you round to the number of digits to the right of
the decimal
if numDigits is < 0, you round the number to the left of the decimal
if numDigits is 0, round the number to an integer
Some examples:
myRound(1000.12534, 2) -- nearest .00
--> 1000.13
myRound(1000.12534, 4) -- nearest .0000
--> 1000.1253
myRound(1005.12534, -1) -- nearest 10
--> 1010.0
myRound(1005.12534, -2) -- nearest 100
--> 1000.0
--
Listserv only address.
Jeff Shapiro
_______________________________________________
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