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: 158

Filed under:

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


Instead of the desired


Can anybody help me?

© Stack Overflow or respective owner

Related posts about c

    Related posts about c++