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

C++ Math llrint()

C++ Math llrint()

该函数使用当前舍入模式舍入给定值,并返回long long int类型的值。

语法

假设数字为" x"。语法为:
long long int llrint(data_type x);

参数

x : 要取整的值。

返回值

它返回四舍五入后的值" x",并且该值的返回类型为long long int。

示例1

让我们看看舍入方向为向上时的简单示例。
#include <iostream>
#include<math.h>
#include<cfenv>
using namespace std;
int main()
{
   float x=5.3;
   std::cout << "Value of x is :" << x<<std::endl;
   fesetround(FE_UPWARD);
   cout<<"Rounded value of x is :"<<llrint(x);
    return 0;
}
输出:
Value of x is :5.3
Rounded value of x is :6   

示例2

让我们看一个简单的示例,取整方向向下。
#include <iostream>
#include<math.h>
#include<cfenv>
using namespace std;
int main()
{
   double x=7.9;
   std::cout << "Value of x is :" << x<<std::endl;
   fesetround(FE_DOWNWARD);
   cout<<"Rounded value of x is :"<<llrint(x);
    return 0;
}
输出:
Value of x is :7.9
Rounded value of x is :7

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