I have a floating point number such as 4917.24. I’d like to print it to always have five characters before the decimal point, with leading zeros, and then three digits after the decimal place.
I tried printf("%05.3f", n) on the embedded system I’m using, but it prints *****. Do I have the format specifier correct?
Your format specifier is incorrect. From the
printf()man page on my machine:For your case, your format would be
%09.3f:Output:
Note that this answer is conditional on your embedded system having a
printf()implementation that is standard-compliant for these details – many embedded environments do not have such an implementation.