C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ Math nearingint()

C++ Math nearingint()

该函数使用当前的舍入方法将给定值舍入为附近的整数值。 fegetround描述了当前的舍入方法。

语法

假设数字是" x"。语法为:
return_type nearbyint(data_type x);
注意: return_type可以是float,double或long double。

参数

x : 该值可以是float或double。

返回值

使用舍入方法将x的舍入值返回到附近的整数值。

示例1

让我们看一个简单的例子。
#include <iostream>
#include<math.h>
#include <cfenv>
using namespace std;
int main()
{
     float x=2.3;
    std::cout << "Value of x is:" <<x<< std::endl;
    cout<<"Rounding to nearby,value is :"<<nearbyint(x);
    return 0;
}
输出:
Value of x is:2.3
Rounding to nearby,value is :2   

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4