devxlogo

Suppress Trailing Zeros on Output

Suppress Trailing Zeros on Output

The format string “%f” in printf() call displays trailing zeros of its argument:

 	float num = 1.33;	printf( "%f", num);  // output: 1.330000

To get rid of the trailing zeros, you should use the “%g” format instead:

 	float num = 1.33;	printf( "%g", num); //output: 1.33

devx-admin

Share the Post: