This approach fails for your given example input of 3.14159:
use strict; use warnings; use Test::More tests => 1; my $val = 3.14159; my $oldval = $val; my $newval = do { use B; if ( not B::SVf_POK & B::svref_2object( \$val )->FLAGS or -1 != index $val, 'e' ) { $val = sprintf '%.4f', $val; $val =~ s/\.?0+$// } "$val" }; is "$oldval", "$newval";
I think you have to either "round to an arbitrarily sane length" as your code does or else just go with the flow.
🦛
In reply to Re^2: Choosing namespace/name for (my first) CPAN module which is a sub-class of a well-known distribution
by hippo
in thread Choosing namespace/name for (my first) CPAN module which is a sub-class of a well-known distribution
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |