llrint(x)函数详解

首页 / C++入门教程 / llrint(x)函数详解

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

llrint - 语法

假设数字是“ x”。语法为:

long long int llrint(data_type x);

llrint - 参数

x :要四舍五入的值。

llrint - 返回值

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

llrint - 例子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   

llrint - 例子2

让我们看一个简单的例子,当舍入方向向下时。

链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-math-llrint-function.html

来源:LearnFk无涯教程网

#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

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

如何设计一个秒杀系统 -〔许令波〕

Swift核心技术与实战 -〔张杰〕

JavaScript核心原理解析 -〔周爱民〕

说透5G -〔杨四昌〕

零基础实战机器学习 -〔黄佳〕

攻克视频技术 -〔李江〕

郭东白的架构课 -〔郭东白〕

深入浅出分布式技术原理 -〔陈现麟〕

结构思考力 · 透过结构看表达 -〔李忠秋〕

好记忆不如烂笔头。留下您的足迹吧 :)