I would like to have a floating point number printed in bash with filled zeros to fill the range of% 5.3f. I know the printf function.
My problem is this:
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 of course I do not want.
Any suggestion?
You should put 0 after % :
0
%
printf "%06.3f\n" 23.00
Note that I also increased the minimum field width to 6, otherwise there will be no padding (3 decimal points, one dot, will leave only one digit in front of the decimal point).
If anything at all, then 0 should be on the right side of the percent sign. I do not have a Linux operating system, but try printf "%05.3f\n" 23.00 .
printf "%05.3f\n" 23.00