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
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist