C ++中的nearint()函数
在本文中,我们将讨论nearbyint()C++STL中函数的工作,语法和示例。
什么nearbyint()啊
附近的int()函数是C++STL中的一个内置函数,该函数在<cmath>头文件中定义。nearbyint()函数用于根据输入获取舍入整数值。
该函数对输入进行舍入以获得最接近的整数值,舍入方法由fegetround描述。
此函数接受float,double和longdouble类型的值作为参数。
语法
double nearbyint(double num); float nearbyint(float num); long double nearbyint(long double num);
参数
该函数接受以下参数-
num-要四舍五入的值。
返回值
此函数返回四舍五入值num。
示例
输入值
nearbyint(2.13);
输出结果
2
输入值
nearbyint(3.4);
输出结果
3
示例
#include <bits/stdc++.h>
using namespace std;
int main(){
float var = 3.4;
cout<<"value of var is: " <<var<< endl;
cout<<"value after round off is: "<<nearbyint(var);
return 0;
}输出结果
value of var is: 3.4 value after round off is: 3
示例
#include <bits/stdc++.h>
using namespace std;
int main(){
float var = 7.9;
cout<<"value of var is: " <<var<< endl;
cout<<"value after round off is: "<<nearbyint(var);
return 0;
}输出结果
value of var is: 7.9 value after round off is: 8
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短