I have two arrays of floating point numbers. One (@nums) contains the full-length version of these numbers. The other (@short_nums) contains these same numbers shortened to 10 deciimal places.
All i am trying to do is find the full-length numbers of a selection of short numbers that are held in a third array (@found).
The problem is that sometimes more than one copy of the numbr is pushed into the array (e.g if two matching numbers in @nums are very similar like 0.005000000000007 and 0.005000000000008).e.g. @nums = ('0.0989999999999', '0.6799999999999', '0.0859999999999', '0.0 +239999999999'); @short_nums = ('0.099', '0.68', '0.086', '0.024'); @found = ('0.099', '0.086'); if (defined ($found[0])) { for (my $i =0; $i<@short_nums; $i++) { if ($found[0] == $short_nums[$i]) { push @new_array, $nums[$i]; } } } # etc ....
How can I ensure only one copy of each matching number is pushed into @new_array?? Thanks x
In reply to testing for numerical equality by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |