Mega Code Archive

 
Categories / C Tutorial / Data Type
 

To create precision with floating-point numbers

%.2f displays only two zeroes after the decimal point. #include <stdio.h> main(){     printf("%.1f", 3.123456);     printf("\n%.2f", 3.123456);     printf("\n%.3f", 3.123456);     printf("\n%.4f", 3.123456);     printf("\n%.5f", 3.123456);     printf("\n%.6f", 3.123456); } 3.1 3.12 3.123 3.1235 3.12346 3.123456