Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Bug? 1+1 != 2

by helgi (Hermit)
on Jun 19, 2003 at 09:29 UTC ( [id://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

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://267114]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-03-29 10:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found