Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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?


--
Regards,
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.

    -Lee

    "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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2014-08-30 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls