Is it possible to make printf print float values like 5.301 and 2.01 without printing extra zeros on the end?
Thanks.
This is a discussion on Printf float printing within the C Programming forums, part of the General Programming Boards category; Is it possible to make printf print float values like 5.301 and 2.01 without printing extra zeros on the end? ...
Is it possible to make printf print float values like 5.301 and 2.01 without printing extra zeros on the end?
Thanks.
What's wrong with %f? it does not print zeroes at the end.
Be more specific what you want to get
If I have eight hours for cutting wood, I spend six sharpening my axe.
printf( "%.2f", .650 );
will print .65 substitute the 2 with 3 or however many digits you want. Keep in mind that it will always be that many digits.
So,
printf( "%.2f", .656 );
will print .66
Not sure if there's a way to make it expand.
//The OPs statement does print zeros on my machine.
glibc version 2.6.1
Last edited by krock923; 12-07-2007 at 11:42 PM.
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^