Avoid trailing zeroes in printf()
Posted
by Gorpik
on Stack Overflow
See other posts from Stack Overflow
or by Gorpik
Published on 2008-11-10T12:42:23Z
Indexed on
2010/03/08
0:52 UTC
Read the original article
Hit count: 388
I keep stumbling on the format specifiers for the printf() family of functions. What I want is to be able to print a double (or float) with a maximum given number of digits after the decimal point. If I use:
printf("%1.3f", 359.01335);
printf("%1.3f", 359.00999);
I get
359.013
359.010
Instead of the desired
359.013
359.01
Can anybody help me?
© Stack Overflow or respective owner