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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -