in reply to number comparison with a twist
This should work?
my $fmt = '%.02f'; if ( sprintf($fmt, $num1) eq sprintf($fmt, $num2) ) { print "they're the same, to two decimal places\n"; }
Another common way is to decide upon a maximum allowable difference between them, for example, 0.005, and compare them like this:
my $diff = 0.005; if ( abs($num1-$num2) < $diff ) { print "they're close enough\n"; }
|
|---|