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

Re: Bug? 1+1 != 2

by helgi (Hermit)
on Jun 19, 2003 at 09:29 UTC ( #267114=note: print w/ replies, xml ) Need Help??

in reply to Bug? 1+1 != 2

The problem is pretty simple, as others have stated and is due to the rounding off of floating point numbers.

The real problem is however, that this is a Very Frequently Asked Question and as such, should be answered in the FAQ.

Of course the question in perlfaq4:

perldoc -q Why am I getting long decimals (eg, 19.9499999999999) inste +ad of the numbers I should be getting (eg, 19.95)?
in essence answers this question, but it could be indexed with a different heading, something like:
Why don't my floating point numbers equal each other?

Helgi Briem
helgi DOT briem AT decode DOT is

Comment on Re: Bug? 1+1 != 2
Select or Download Code
Re: Re: Bug? 1+1 != 2
by shotgunefx (Parson) on Jun 19, 2003 at 10:59 UTC
    I figured it was along those lines as "eq" worked. Any idea on how Perl decides to format the stringified number? I looked at $# but it says it's depreciated so I would think it lies elsewhere.


    "To be civilized is to deny one's nature."
      The internal decision about how Perl "stringifies" floats are quite well described in perlnumber; if you need different conversions, you have to resort to printf and explicit rounding.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2015-01-25 05:21 GMT
Find Nodes?
    Voting Booth?

    My top resolution in 2015 is:

    Results (180 votes), past polls