此函數用於四舍五入給定值並轉換為長整數。
用法
假設一個數字是 'x'。語法是:
long int lround(data_type x);
參數
x:值可以是浮點數或雙精度數。
返回值
它返回 x 的舍入值。函數的返回類型是 long int。
例子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
相關用法
- C++ Math lrint()用法及代碼示例
- C++ Math log2()用法及代碼示例
- C++ Math log()用法及代碼示例
- C++ Math log10()用法及代碼示例
- C++ Math logb()用法及代碼示例
- C++ Math llround()用法及代碼示例
- C++ Math less()用法及代碼示例
- C++ Math lgamma()用法及代碼示例
- C++ Math log1p()用法及代碼示例
- C++ Math llrint()用法及代碼示例
- C++ Math scalbn()用法及代碼示例
- C++ Math acosh()用法及代碼示例
- C++ Math asinh()用法及代碼示例
- C++ Math isgreater()用法及代碼示例
- C++ Math fabs()用法及代碼示例
- C++ Math islessgreater()用法及代碼示例
- C++ Math nearbyint()用法及代碼示例
- C++ Math tan()用法及代碼示例
- C++ Math nextafter()用法及代碼示例
- C++ Math fdim()用法及代碼示例
注:本文由純淨天空篩選整理自 C++ Math lround()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。