• 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” command rounding algorithms
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: “round” command rounding algorithms


  • Subject: Re: “round” command rounding algorithms
  • From: Chris Page <email@hidden>
  • Date: Thu, 04 Jun 2009 21:09:43 -0700

On Jun 4, 2009, at 4:31 PM, Doug McNutt wrote:

And my biggest problem is Apple's "rounding as taught in school". I was never taught anything like that and I really would like to know Apple's rules for remainders that are exactly 1/2 of a digit or for negative values.

If that’s your biggest problem, you’re doing fantastically. ;-)

 (I was taught, in school, that -2^2 was a negative number but that's another question.)

See my other reply, about Minus-Hypen, et al.

Wikipedia has a good article on rounding and various algorithms:

<http://en.wikipedia.org/wiki/Rounding>

The “round” command has a “rounding” parameter that lets you control which algorithm is used. The “as taught in school” algorithm is the one I was taught in elementary school.

<http://developer.apple.com/documentation/applescript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW43>

rounding roundingDirection

The direction to round. You may specify one of the following rounding directions:

up

Rounds to the next largest integer. This is the same as the math “ceiling” function.

down

Rounds down to the next smallest integer. This is the same as the math “floor” function.

toward zero

Rounds toward zero, discarding any fractional part. Also known as truncation.

to nearest

Rounds to the nearest integer; .5 cases are rounded to the nearest even integer. For example, 1.5 rounds to 2, 0.5 rounds to 0. Also known as “unbiased rounding” or “bankers’ rounding.” See Discussion for details.

as taught in school

Rounds to the nearest integer; .5 cases are rounded away from zero. This matches the rules commonly taught in elementary mathematics classes.

Default Value:

to nearest


-- 
Chris Page

 The other, other AppleScript Chris

 _______________________________________________
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: Same code gives different answers in 2 different scripts (From: Shane Stanley <email@hidden>)
 >Re: Same code gives different answers in 2 different scripts (From: Doug McNutt <email@hidden>)

  • Prev by Date: Re: Minus-Hyphen, Numeric Negation and Subtraction
  • Next by Date: Re: Operator vs. Command precedence
  • Previous by thread: Re: Minus-Hyphen, Numeric Negation and Subtraction
  • Next by thread: Re: Same code gives different answers in 2 different scripts
  • Index(es):
    • Date
    • Thread