in reply to Round numbers?
Update: This loop produces the same output without needing an intermediate variable:>perl -wMstrict -le "my @nra = ( 8.8458e-119, 1.06542e-52, 2.68e-36, 2.91405e-35, 0.0190644, 0.0205511, 0.004, ); for my $n (@nra) { my $fmt = $n > 0.001 ? '%5.2g' : '%5.3g'; printf qq{$fmt \n}, $n; } " 8.85e-119 1.07e-052 2.68e-036 2.91e-035 0.019 0.021 0.004
printf qq{%5.*g \n}, $_ > 0.001 ? 2 : 3, $_ for @nra;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Round numbers?
by Anonymous Monk on Oct 01, 2009 at 23:48 UTC | |
by AnomalousMonk (Archbishop) on Oct 02, 2009 at 00:05 UTC | |
by Anonymous Monk on Oct 02, 2009 at 00:51 UTC |