in reply to counter-intuitive sprintf behaviour

Besides all the answers in this thread so far of "binary representation of decimal fractions is inexact", I saw a few puzzles that were cleanly answered by another often-forgotten fact:
Rounding of a value that is exactly halfway between two whole numbers will always go to the nearest even number.
This is mandated by mathematicians in an attempt to reduce round-off error.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

  • Comment on •Re: counter-intuitive sprintf behaviour

Replies are listed 'Best First'.
Re: •Re: counter-intuitive sprintf behaviour
by Anonymous Monk on Jan 15, 2003 at 05:45 UTC
    Rounding of a value that is exactly halfway between two whole numbers will always go to the nearest even number.
    Only when the radix/2 is odd (e.g. base 2 or base 10)
    When the radix is a multiple of 4, rounding to the nearest odd number is preferred.