四舍五入输出2.35
1 int main() { 2 double a = 2.345; 3 printf("%.2f\n", a); 4 return 0; 5 }
截断输出2.34
1 int main() { 2 double a = 2.345; 3 a = int(a * 100) / 100.0; 4 printf("%.2f\n", a); 5 return 0; 6 }