C++ cmath round() 函数
定义和用法
round()
函数将数字四舍五入到最近的整数。如果小数部分恰好为 0.5,则向绝对值最大的整数方向四舍五入(即远离零的方向)。
round()
函数在 <cmath>
头文件中定义。
实例
将数字四舍五入到最近的整数:
cout << round(0.60); cout << round(0.40); cout << round(5); cout << round(5.1); cout << round(-5.1); cout << round(-5.9);
语法
以下之一:
round(double number);
round(float number);
参数
参数 | 描述 |
---|---|
number |
必需。指定一个数字。 如果数字是整数类型,则会被视为 |
技术细节
返回: |
如果参数是 否则返回 |
---|