in reply to number comparison with a twist
I am assuming you know What Every Computer Scientist Should Know About Floating-Point Arithmetic, since you say "this fails due to the way floats are stored in memory". On the off-chance you (or a future reader) needs a refresher, I have included the link.
Since the prices are coming as floats-in-a-string, you have it easy: you should just be able to strip out the decimal point. Assuming it's always got exactly two digits following, $price_string =~ s/\.(\d{2})$/$1/;. After this, it will be in string and numeric form as integer cents. parv already posted a regex that just strips the decimal point from anywhere in the string.
Alternately, don't use the int, which does truncation; instead, use a round-to-nearest, like round of POSIX
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: number comparison with a twist
by anotherguest (Novice) on Mar 02, 2020 at 15:29 UTC | |
by parv (Parson) on Mar 02, 2020 at 15:42 UTC | |
by anotherguest (Novice) on Mar 02, 2020 at 15:54 UTC | |
by pryrt (Abbot) on Mar 02, 2020 at 16:10 UTC | |
by LanX (Saint) on Mar 02, 2020 at 17:57 UTC |
In Section
Seekers of Perl Wisdom