四舍五入
来源:互联网 发布:谷歌翻译软件 编辑:程序博客网 时间:2024/03/29 09:46
#include <iostream>
#include <math.h>
using
namespace
std;
int
main()
{
double
num;
while
(cin >> num)
{
//方法一
int
tmp =
int
(num);
if
(num - tmp >= 0.5)
cout << tmp + 1 << endl;
else
cout << tmp << endl;
//方法二
//
cout << int( num +0.5 )<< endl;
//方法三
//
cout << round(num) << endl;
}
return
0;
}
注意:Round():返回按指定位数进行四舍五入的数值。
Round(number, num_digits):
number 必需。要四舍五入的数字。
num_digits 必需。位数,按此位数对 number 参数进行四舍五入。
0 0