will cause the key accessed to be a floating point number with 3 decimal places, thus forcing the numbers to yield appropriate strings. It also avoids the potential 6.269999999999999999 problem.$ifac{sprintf "%.3f" $factor}
In your case, your issue begins with your hash creation:
printsuse Data::Dumper; my %ifac= ( 14.152 => "JCI", 9.334 => "JHEP", 5.745 => "JIMM", 6.270 => "JID", 1.480 => "JRN", 6.105 => "KI" ); print Dumper \%ifac;
You need to control string format on input, which means using strings not numbers for initialization:$VAR1 = { '6.105' => 'KI', '1.48' => 'JRN', '9.334' => 'JHEP', '5.745' => 'JIMM', '6.27' => 'JID', '14.152' => 'JCI' };
my %ifac= ( '14.152' => "JCI", '9.334' => "JHEP", '5.745' => "JIMM", '6.270' => "JID", '1.480' => "JRN", '6.105' => "KI" );
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
In reply to Re: decimal numbers as hash keys
by kennethk
in thread decimal numbers as hash keys
by Alex31
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |