floor(-1.8)和round(-1.8)的执行结果都是-2.
floor(-1.8)=-2; round(-1.8)=-2;
constchar* format ="%.1f \t%.1f \t%.1f \t%.1f \t%.1f\n";
printf ("value\tround\tfloor\tceil\ttrunc\n");
printf ("-----\t-----\t-----\t----\t-----\n");
printf (format, 2.3,round( 2.3),floor( 2.3),ceil( 2.3),trunc( 2.3));
printf (format, 1.8,round( 1.8),floor( 1.8),ceil( 1.8),trunc( 1.8));
printf (format, 5.5,round( 5.5),floor( 5.5),ceil( 5.5),trunc( 5.5));
printf (format,-2.3,round(-2.3),floor(-2.3),ceil(-2.3),trunc(-2.3));
printf (format,-1.8,round(-1.8),floor(-1.8),ceil(-1.8),trunc(-1.8));
value round floor ceil trunc
----- ----- ----- ---- -----
2.3 2.0 2.0 3.0 2.0
1.8 2.0 1.0 2.0 1.0
5.5 6.0 5.0 6.0 5.0
-2.3 -2.0 -3.0 -2.0 -2.0
-1.8 -2.0 -2.0 -1.0 -1.0
温馨提示:答案为网友推荐,仅供参考