• 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: Rounding off in AppleScript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rounding off in AppleScript


  • Subject: Re: Rounding off in AppleScript
  • From: Paul Berkowitz <email@hidden>
  • Date: Tue, 12 Apr 2005 20:33:38 -0700

Why do you see that as an advantage, Scott? To do one or a few roundings
makes no difference for efficiency, but to do hundreds in a repeat loop you
would be _much_ better off using Vince's script "adding 0.5 and applying
integer division by 1". 'round' is a scripting addition call, and will be
close to 100 times slower than pure AppleScript. Easier to read, true, so if
you're just doing it once or a few times, by all means use it.

--
Paul Berkowitz


> From: Scott Babcock <email@hidden>
> Date: Tue, 12 Apr 2005 20:13:51 -0700
> To: <email@hidden>
> Subject: RE: Rounding off in AppleScript
>
> Try this:
>
> on RoundOff(num, precis)
>     set factor to 10 ^ precis
>     return ((round(num * factor)) / factor)
> end RoundOff
>
> This uses the 'round' osax instead of adding 0.5 and applying integer
> division by 1. The asax works correctly for negative numbers as well as
> positive numbers, rounding to the nearest integer.
>
> -----Original Message-----
> Hello list,
>
> Does there exist any AppleScript primitive that rounds off a floating
> point number up to a desired number of decimal points, e.g.
>
> RoundOff(4.213452, 2)
>
> Could round off the number and return me 4.21
>
> And similarly
>
> RoundOff(4.98123, 0)
>  Returns me 5.00
>
> TIA.
>  _______________________________________________
> 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
>


 _______________________________________________
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: 
 >RE: Rounding off in AppleScript (From: "Scott Babcock" <email@hidden>)

  • Prev by Date: RE: Rounding off in AppleScript
  • Next by Date: Re: Question on AppleScript w/ QuarkXPress 4
  • Previous by thread: RE: Rounding off in AppleScript
  • Next by thread: Re: Rounding off in AppleScript
  • Index(es):
    • Date
    • Thread