lround(x)函数详解

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

此函数用于舍入给定值并将其转换为长整数。

lround - 语法

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

long int lround(data_type x);

lround - 参数

x :该值可以是float或double。

lround - 返回值

它返回x的舍入值。该函数的返回类型为long int。

lround - 例子1

让我们看一个使用lround()函数的简单示例

#include <iostream>  
#include<math.h>  
using namespace std;  
int main()  
{  
    float x=2.3;  
    double y=-12.6;  
    float z=23.6;  
    std::cout << "The value of x is : " <<x<< std::endl;  
    std::cout << "The value of y is : " <<y<< std::endl;  
    std::cout << "The value of z is : " <<z<< std::endl;  
    cout<<"Rounded value of x is : "<<lround(x)<< std::endl;  
    cout<<"Rounded value of y is : "<<lround(y)<< std::endl;  
    cout<<"Rounded value of z is : "<<lround(z)<< std::endl;  
    return 0;  
}  

输出:

The value of x is : 2.3
The value of y is : -12.6
The value of z is : 23.6
Rounded value of x is : 2
Rounded value of y is : -13
Rounded value of z is : 24

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

技术教程推荐

AI技术内参 -〔洪亮劼〕

邱岳的产品手记 -〔邱岳〕

Web协议详解与抓包实战 -〔陶辉〕

编译原理之美 -〔宫文学〕

分布式系统案例课 -〔杨波〕

动态规划面试宝典 -〔卢誉声〕

MySQL 必知必会 -〔朱晓峰〕

说透5G -〔杨四昌〕

LangChain 实战课 -〔黄佳〕

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