I can't see this mentioned in the manual for GNU awk, but e.g. man page for the
printf() function in glibc mentions about
Trailing zeros are removed from the fractional part of the result; a decimal point appears only if it is followed by at least one digit.
Also, there's the
# modifier for an "alternate format", which says:
For g and G conversions, trailing zeros are not removed from the result as they would otherwise be.
%g automatically changes to the
1.23e+3 format as necessary, and the precision field (the number after the dot) is "the maximum number of significant digits for g and G conversions" (not digits after the decimal point), so we get:
printf "%#.1g\n", 0 0.
printf "%#.2g\n", 0 0.0
printf "%#.2g\n", 12 12.
printf "%#.2g\n", 1234 1.2e+03
so while you can force the decimal point to appear, you can't force a trailing zero to appear.
An alternative would be to use
printf "%.1f\n", 0 0.0
printf "%.1f\n", 1234 1234.0
Or to add the missing zero after the dot as necessary:
a = sprintf("%#.1g", 0); if (substr(a, length(a)) == ".") a = a "0";