I would like to have a floating point number printed in bash with padded zeroes to fill a range %5.3f.
I know of printf function.
My problem is the following:
printf "0%5.3f\n" 3.00
returns, as expected,
03.000
but the line
printf "0%5.3f\n" 23.00
gives instead
023.000
which is not what I want of course.
Any suggestion?
You have to put the
0after the%:Notice that I also increased the minimum field width to 6, otherwise no padding will occur (3 decimal places, one dot, leaves just a single digit in front of the decimal point).