c语言ceiling的使用方法,C# 用法及代码示例

时间:2025-03-23 11:58:19

在C#中,()是Math类方法。此方法用于查找最小整数,该整数大于或等于传递的参数。 Celing方法同时使用十进制和双精度两种功能。通过向其传递不同的参数,可以使其重载。

(Decimal)方法

(Double)方法

(Decimal) Method

此方法用于返回最小整数值,该整数值大于或等于参数列表中指定的十进制数。

用法:

public static decimal Ceiling(decimal d)

参数:

Decimal d:它是类型的十进制数。

返回类型:此函数返回最小的整数值,该值将大于或等于d。此方法的类型为,并返回小数而不是整数类型。

例子:

Input : 888.765M;

Output : 889

Input : -20002.999M

Output : -20002

程序:演示(Decimal)方法。

// C# program to illustrate the

// (Decimal) function

using System;

class SudoPlacement {

// Main method

static void Main()

{

// Input decimal value.

decimal decim_n1 = 2.10M;

decimal decim_n2 = -99.90M;

decimal decim_n3 = 33.001M;

// Calculate Ceiling values by

// Using () function

decimal ceil_t1 = (decim_n1);

decimal ceil_t2 = (decim_n2);

decimal ceil_t3 = (decim_n3);

// Print First values and Ceiling

("Input Value  = " + decim_n1);

("Ceiling value = " + ceil_t1);

// Print Second values and Ceiling

("Input Value  = " + decim_n2);

("Ceiling value = " + ceil_t2);

// Print third values and Ceiling

("Input Value  = " + decim_n3);

("Ceiling value = " + ceil_t3);

}

}

输出:

Input Value = 2.10

Ceiling value = 3

Input Value = -99.90

Ceiling value = -99

Input Value = 33.001

Ceiling value = 34

(Double) Method

此方法用于返回最小整数值,该整数值大于或等于参数列表中指定的双精度浮点数。

用法:

public static double Ceiling(double d)

参数:

Double d:它是类型的双精度数字。

返回类型:此方法返回大于或等于d的最小积分值。如果d等于NaN,NegativeInfinity或PositiveInfinity,则返回该值。此方法的类型为。

例子:

Input : 10.1

Output : 11

Input : -2222.2220

Output : -2222

程序:演示(Double)方法。

// C# program to illustrate the

// (Double) function

using System;

class SudoPlacement {

// Main method

static void Main()

{

// Input different Double value.

double n1 = 101.10;

double n2 = -1.1;

double n3 = 9222.1000;

// Calculate Ceiling values by

// Using () function

double t1 = (n1);

double t2 = (n2);

double t3 = (n3);

// Print First values and Ceiling

("Input Value  = " + n1);

("Ceiling value = " + t1);

// Print Second values and Ceiling

("Input Value  = " + n2);

("Ceiling value = " + t2);

// Print third values and Ceiling

("Input Value  = " + n3);

("Ceiling value = " + t3);

}

}

输出:

Input Value = 101.1

Ceiling value = 102

Input Value = -1.1

Ceiling value = -1

Input Value = 9222.1

Ceiling value = 9223

参考文献: