Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: How to use the int-function?

by moritz (Cardinal)
on Jan 03, 2011 at 15:02 UTC ( [id://880199]=note: print w/replies, xml ) Need Help??


in reply to How to use the int-function?

Please read What Every Computer Scientist Should Know About Floating-Point Arithmetic. The problem is not that int is misbehaving, but that the numbers aren't as exact as they appear.

Perl rounds them upon printing, it looks like an even number, but it is not.

$ perl -wE 'say +(1.255 * 100 + 0.5) * 10000000' 1260000000 $ perl -wE 'printf "%.20f\n", (1.255 * 100 + 0.5) * 10000000' 1259999999.99999976158142089844

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-18 01:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found