bash - Why does printf (Unix) use round half down? -
why printf behave in such uncommon way?
> printf %.0f 2.5 > 2 > printf %.0f 2.51 > 3
is there advantage of behaviour compensates probable misunderstandings (like this one)?
it's not strictly round-down:
> printf '%.0f\n' 2.5 2 > printf '%.0f\n' 3.5 4
this form of rounding used combat bias if rounding large number of values; half of them rounded down, other half rounded up. rule is, round down if integer portion even, if integer portion odd.
this is, however, explanation of particular rounding scheme, not guaranteed used implementations of printf
.
Comments
Post a Comment