good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re^2: perl floating number additionby Albannach (Monsignor) |
on Jul 18, 2009 at 13:49 UTC ( [id://781324]=note: print w/replies, xml ) | Need Help?? |
A (pretty common) nit to pick here: the 3 in %3.2f is not the number of digits before the decimal, it's the minimum total width of the resulting field, including the decimal. So if you really want 3 digits, a decimal and 2 digits, then you need %6.2f. This is a minimum and the digits to the left of the decimal will still be printed, so your example of 895.3 still appears to work (even though it would be better described as %5.1f), but try that in a table and you'll find that the column won't line up when another value is just 1.23 for instance.
For illustration, printf("%3.2f\n",$_) for (3.2,32.2,322.2) gives:
while printf("%6.2f\n",$_) for (3.2,32.2,322.2) gives:
--
In Section
Seekers of Perl Wisdom
|
|