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.
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Math 101 anyone?
by davido (Cardinal) on Oct 12, 2004 at 07:44 UTC | |
Re: Math 101 anyone?
by BrowserUk (Patriarch) on Oct 12, 2004 at 08:10 UTC | |
by bpphillips (Friar) on Oct 12, 2004 at 12:42 UTC | |
by BrowserUk (Patriarch) on Oct 12, 2004 at 13:10 UTC | |
by bpphillips (Friar) on Oct 12, 2004 at 14:57 UTC | |
Re: Math 101 anyone?
by Crian (Curate) on Oct 12, 2004 at 07:46 UTC | |
Re: Math 101 anyone?
by kvale (Monsignor) on Oct 12, 2004 at 07:51 UTC | |
by muntfish (Chaplain) on Oct 12, 2004 at 08:14 UTC | |
Re: Math 101 anyone?
by SpanishInquisition (Pilgrim) on Oct 12, 2004 at 13:43 UTC | |
Re: Math 101 anyone?
by Preceptor (Deacon) on Oct 12, 2004 at 19:33 UTC | |
Re: Math 101 anyone?
by gawatkins (Monsignor) on Oct 12, 2004 at 20:10 UTC | |
Re: Math 101 anyone?
by Crian (Curate) on Oct 13, 2004 at 09:23 UTC | |
by BrowserUk (Patriarch) on Oct 13, 2004 at 09:28 UTC |
Back to
Seekers of Perl Wisdom