Formatting fixed decimal scalar
I have been experimenting with sprintf trying to fix the number of digits
to the right of the decimal place as well as to the left.
The following works, but does not handle 0.00 well. As you can see, 0.00
does not align correctly like all the other non-zero decimal values.
sprintf("%.2f ", $sw_chgs)
535.14 642.90 20.31 1198.35
442.74 531.90 20.31 994.95
0.00 0.00 0.00 0.00
If if I add a field width or designator like %6f to the sprintf, "2f" is
printed after the decimal place.
sprintf("%6f.2f ", $ws_chgs
244.100000.2f
I want to do something like the following which limits the whole number's
field width
sprintf("%6d ", $prev_rd)
Is that possible with a decimal value?
No comments:
Post a Comment