in reply to Re: Rounding to a Given Number of Significant Figures Rather Than Decimal Places
in thread Rounding to a Given Number of Significant Figures Rather Than Decimal Places
Update: Urm... that will replace the leading zero with a space, which is only part of your problem... Apparently, the default precision offered by "%g" is smaller than the precision you desire.
OK, try this:
Result:$_ = 1298.844667; my $clem = sprintf("%.7g", $_); print "$clem\n";
OK?1298.845
|
|---|