亚洲区国产区激情区无码区,国产成人mv视频在线观看,国产A毛片AAAAAA,亚洲精品国产首次亮相在线

C++ 基礎(chǔ)教程

C++ 流程控制

C++ 函數(shù)

C++ 數(shù)組 & 字符串

C++ 數(shù)據(jù)結(jié)構(gòu)

C++ 類 & 對(duì)象

C++ 指針

C++ 繼承

C++ STL 教程

C++ 參考手冊(cè)

C++ llround() 函數(shù)使用方法及示例

C++ 庫(kù)函數(shù) <cmath>

C ++中的llround()函數(shù)將浮點(diǎn)值舍入為最接近的整數(shù)。返回的值是long long int類型。它類似于lround()函數(shù),但返回long long int,而lround返回long int。

llround()原型[從C ++ 11標(biāo)準(zhǔn)開始]

long long int llround(double x);
long long int llround(float x);
long long int llround(long double x);
long long int llround(T x); //為整型

llround()函數(shù)采用單個(gè)參數(shù),并返回long long int類型的值。此函數(shù)在<cmath>頭文件中定義。

llround()參數(shù)

llround()函數(shù)將單個(gè)參數(shù)值取整。

llround()返回值

llround()函數(shù)返回最接近x的整數(shù)值,中間情況下從零舍入。返回的值是long long int類型。

示例1:llround()在C ++中如何工作?

#include <iostream>
#include <cmath>

using namespace std;

int main()
{   
    long long int result;
    double x = 11.16;
    result = llround(x);
    cout << "llround(" << x << ") = " << result << endl;

    x = 13.87;
    result = llround(x);
    cout << "llround(" << x << ") = " << result << endl;
    
    x = 50.5;
    result = llround(x);
    cout << "llround(" << x << ") = " << result << endl;
    
    x = -11.16;
    result = llround(x);
    cout << "llround(" << x << ") = " << result << endl;

    x = -13.87;
    result = llround(x);
    cout << "llround(" << x << ") = " << result << endl;
    
    x = -50.5;
    result = llround(x);
    cout << "llround(" << x << ") = " << result << endl;
    
    return 0;
}

運(yùn)行該程序時(shí),輸出為:

llround(11.16) = 11
llround(13.87) = 14
llround(50.5) = 51
llround(-11.16) = -11
llround(-13.87) = -14
llround(-50.5) = -51

示例2:整數(shù)類型的llround()函數(shù)

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int x = 15;
    long long int result;
    result = llround(x);
    cout << "llround(" << x << ") = " << result << endl;

    return 0;
}

運(yùn)行該程序時(shí),輸出為:

llround(15) = 15

對(duì)于整數(shù)值,應(yīng)用llround函數(shù)將返回與輸入相同的值。所以它在實(shí)際中并不常用來表示整數(shù)值。

C++ 庫(kù)函數(shù) <cmath>