in reply to testing for numerical equality
output:use strict; use warnings; my @nums = qw( 0.0989999999999 0.0981111111111 0.6799999999999 0.0859999999999 0.0239999999999 0.0239999999993 ); my @found = qw( 0.099 0.086 0.024 ); # create a hash, with the rounded number as the key, and # the original number as the value # Note that it only store a single value, so only the last # original number is stored. my %short_nums = map { sprintf("%.3f", $_) => $_ } @nums; foreach my $short (@found) { if(exists $short_nums{$short}) { print "Long num for $short = ", $short_nums{$short}, "\n"; } else { print "No matching long num for $short ...\n"; } }
... and if you do care about the lose of the original number, then there is no solution :)Long num for 0.099 = 0.0989999999999 Long num for 0.086 = 0.0859999999999 Long num for 0.024 = 0.0239999999993
|
---|