in reply to [s]printf %d oddity
why doesn't the %3.5f example print 877.99999?
Because %f rounds. (%d truncates.)
>perl -e "printf '%.16f', 8.78" 8.7799999999999994 >perl -e "printf '%.5f', 8.78" 8.78000 >perl -e "printf '%d', 4.7" 4 >perl -e "printf '%.0f', 4.7" 5 >perl -e "printf '%d', -4.7" -4 >perl -e "printf '%.0f', -4.7" -5
And why does multiplying by 1000 make a difference for the %08d version?
If I were to guess, the floating point processor is forced to discard low-precision bits, and it rounds the result when it does so.
|
|---|