+ 1
Printf float in C
How do I trim the "0" after the coma while printing a float? Setting a precision doesn't work sufficiently because sometimes I need to display four digits after the coma, sometimes it's just two. My float is being divided so I can't predict the exact precision I need, but I need to display it in the shortest form possible without rounding.
1 Answer
+ 2
Try "%g"
#include <stdio.h>
int main() {
float num1 = 1.39000;
printf("%g", num1);
return 0;
}