|laziness, impatience, and hubris|
Math 101 anyone?by smcone (Acolyte)
|on Oct 12, 2004 at 07:38 UTC||Need Help??|
smcone has asked for the
wisdom of the Perl Monks concerning the following question:
Hello Perl Monks -
I am a new user to this site - but a professional programmer for many years - hope I can be a vital contributor to your esteemed collection of knowledge.
I have a simple math question.
I recently stumbled upon a very obscure problem in one of my apps.
According to Perl,
100.10 - 100.00 = 0.0999999999999943
and not ".10" as I would have imagined from my early school days.
Try it yourself in your favorite shell (this happens in v5.83):
perl -e "print (100.10-100);"
Can someone with supreme wisdom please explain to me why perl comes to this result from simple math with a non-whole number. This is causing thousands of calculations in my app to be off by .01 - .02 - but when money is involved it needs to be 100% correct.
Is this a perl bug? Or am I missing something completely obvious?
Look forward to your replies.