P is for Practical | |
PerlMonks |
Re: number comparison with a twistby BillKSmith (Monsignor) |
on Mar 02, 2020 at 15:35 UTC ( [id://11113639]=note: print w/replies, xml ) | Need Help?? |
It is almost never a good idea to test floating point numbers for equality. We can assume that they are 'equal' if their difference is 'sufficiently' small. The definition of 'sufficient' depends on the application. In your case, .01 cent is probably sufficient. This is far larger than any error introduced by floating point. For your current question, this method would use far more of your existing code than any of the exact methods proposed by other monks.
Bill
In Section
Seekers of Perl Wisdom
|
|