Decimal Padding in Decimal

Hi Experts,

I have requirement to pad a decimal number that should have fixed length as 10.
if number is 234.234 > 234.234000
if number is 12.4 > 12.4000000
if number is 3456.5678 > 3456.56780

from above example we can see that overall length is 10 and padding is being done right sided of decimal part.
Kindly help me on this.
Thanks,

Hi, in bash/ksh93/zsh :

num=23544.2
num10=$(printf "%-10s" "$num")
printf "%s\n" "${num10// /0}"

I assumed you mean a value in a variable in a shell script, and that the number length including dot is <=10 because you did not specify..

1 Like

Or

awk '{printf "%*.*f\n", FL, FL-1-length(int($1)), $1}' FL=10 file
234.234000
12.4000000
3456.56780
1 Like