当前位置: C语言 -- 标准库 -- <math.h> -- llround

llround函数


概要:
#include <math.h>
long long int llround(double x);

描述:

该函数将参数x舍入为long long int类型的最近整数值;如果参数x位于两个整数的正中间,将向远离0的方向舍入。

如果舍入得到的值超出返回类型所能表示的范围,结果是不明确的,并且可能发生域错误或者范围错误(range error)


参数:
double x

参数为一个double类型的浮点数。


返回值:

函数返回long long int类型的舍入得到的整数值。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
/*函数llround范例*/

#include <math.h>
#include <stdio.h>

int main(void)
{
    printf("llround(2.3) = %lld\n", llround(2.3));
    printf("llround(2.7) = %lld\n", llround(2.7));
    printf("llround(2.5) = %lld\n", llround(2.5));
    printf("llround(-2.5) = %lld\n", llround(-2.5));

    return 0;
}


输出:

llround(2.3) = 2

llround(2.7) = 3

llround(2.5) = 3

llround(-2.5) = -3


相关内容:
llroundf float类型参数舍入为最近整数值的函数。
llroundl long double类型参数舍入为最近整数值的函数。