Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re^5: number comparison with a twistby pryrt (Abbot) |
on Mar 05, 2020 at 15:09 UTC ( [id://11113855]=note: print w/replies, xml ) | Need Help?? |
No, truncation is correct in this case. ... as the rounding error seen in my original post was introduced by storing the string representation into a binary float Whatever works for you. I am just saying that not all price strings translate into a double that is bigger than the string value, and you will want to make sure that your application doesn't have any situations like the following, for the string "1.13", which has a binary representation slightly less than 1.13 for both double precision and single precision:
If your application doesn't have that problem, then great. However, I still don't see why my suggestion won't work for you. It would be nice for you to show me one example of a price-string to put in $from_api that will not become the right integer number of cents when run through my second section of code:
Here's a testbed, showing that for reasonable strings, our two match. It also shows a couple strange variants, where there's at least one place where your truncation and my rounding come up with different results.
In Section
Seekers of Perl Wisdom
|
|