Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: A bug of sprintf or not?

by ikegami (Patriarch)
on Oct 20, 2008 at 10:20 UTC ( #718188=note: print w/replies, xml ) Need Help??

in reply to A bug of sprintf or not?

Anonymous Monk is mistaken. This isn't a precision issue. It's banker's rounding.
printf("%.0f\n", 100.5); # 100 printf("%.0f\n", 101.5); # 102 printf("%.0f\n", 102.5); # 102 printf("%.0f\n", 103.5); # 104 printf("%.0f\n", 104.5); # 104 printf("%.0f\n", 105.5); # 106

Note that all those numbers (but not 100.55) can be represented precisely in floats (0.5 = 2-1).

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://718188]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2023-06-06 16:54 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (29 votes). Check out past polls.