Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: A bug of sprintf or not?

by ikegami (Patriarch)
on Oct 20, 2008 at 10:20 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-20 12:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found