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 0
after the %
:
printf "%06.3f\n" 23.00
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).
If anything at all, the 0 would have to be on the right side of the percent sign. I don't have a linux system at work, but try printf "%05.3f\n" 23.00
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With