在C++中,round()
函数是一个数学函数,用于对浮点数进行四舍五入。它位于 <cmath>
头文件中。
在C++中,round()
函数的声明如下:
double round(double x);
float round(float x);
long double round(long double x);
其中,x
是要进行四舍五入的浮点数。
使用示例:
#include<iostream>
#include <cmath>
int main() {
double num = 3.14159;
double rounded_num = round(num);
std::cout << "Rounded number: "<< rounded_num<< std::endl;
return 0;
}
输出:
Rounded number: 3
在这个示例中,我们使用了 <cmath>
头文件中的 round()
函数,将 3.14159
四舍五入为 3
。
算法大赛
云+社区沙龙online [技术应变力]
云+社区沙龙online [新技术实践]
云+社区沙龙online [国产数据库]
腾讯数字政务云端系列直播
企业创新在线学堂
领取专属 10元无门槛券
手把手带您无忧上云