in reply to number comparison with a twist

Supposing your float has always exactly two decimal points

I'd convert the textual float to textual cents by eliminating the dot .

Like this you'll only deal with integers.

I might even try to only use eq for comparison then, but this depends on the accuracy of your format (leading zeroes and so on)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: number comparison with a twist
by Marshall (Canon) on Mar 05, 2020 at 04:10 UTC
    I like this answer.
    The input is NOT a float, it is a string of decimal digits which could potentially be represented by a binary float.
    I would move the decimal 2 places to the right, 12.=>1200, 12.3=>1230 and see if any non-zero digits remain. If so, there are going to be problems when comparing numbers. I would not convert "12.30" to a float unless you have to.

    This API is giving the OP a decimal character string instead of a much more compact, efficient binary float. I suspect that there are reasons behind that the OP hasn't told us. This string could have come from some BCD (Binary Coded Decimal) calculation or whatever. I have never written any BCD code, but yes there are math operations that modern processors can do on arrays of BCD's (every 4 bits only goes 0-9 instead of 0-F).