• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Round a number towards zero!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Round a number towards zero! (From: Marcus Rodrigues <email@hidden>)
 >Re: Round a number towards zero! (From: yvan-koenig <email@hidden>)
 >Re: Round a number towards zero! (From: Christian Vinaa <email@hidden>)

  • Prev by Date: Re: Mail.app script help needed
  • Next by Date: Re: .acgi & form to send vars to an APP
  • Previous by thread: Re: Round a number towards zero!
  • Next by thread: Re: Round a number towards zero!
  • Index(es):
    • Date
    • Thread