• 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: Coercing Numbers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Coercing Numbers


  • Subject: Re: Coercing Numbers
  • From: "Stockly, Ed" <email@hidden>
  • Date: Fri, 26 Feb 2010 12:44:40 -0800
  • Thread-topic: Coercing Numbers

Title: Re: Coercing Numbers
set x to 124.956 * 100 as integer

The correct answer is 12495.6, but the script returns 12396.

In that case this might be a better solution:

set x to round (124.95 * 100)

Because it gives you those nifty options:
set x to round (124.955 * 100)
set
x to round (124.955 * 100) rounding up
set x to round (124.955 * 100) rounding down
set x to round (124.955 * 100) rounding toward zero
set x to round (124.955 * 100) rounding as taught in school
set x to round (124.955 * 100) rounding to nearest --the default

Rounding direction, if omitted, rounds to nearest.
“to nearest” rounds .5 cases to the nearest even integer in order to decrease cumulative errors.
To always round .5 away from zero, use “as taught in school.”


HTH,

ES
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Re: Coercing Numbers (From: Michelle Steiner <email@hidden>)

  • Prev by Date: Re: Coercing Numbers
  • Next by Date: Re: [ANN] AppleScript Pro Sessions Florida
  • Previous by thread: Re: Coercing Numbers
  • Next by thread: Re: Coercing Numbers
  • Index(es):
    • Date
    • Thread