此方法用于将小数点四舍五入为正无穷大的最接近的整数。
Syntax: public static decimal Ceiling (decimal d);
Here d is the decimal whose ceiling value is to be calculated.
Return Value: It returns the smallest integral value that is greater than or equal to the d parameter. Note that this method returns a Decimal instead of an integral type.
下面的程序说明了Decimal.Ceiling(Decimal)方法的用法:
范例1:
// C# program to demonstrate the
// Decimal.Ceiling(Decimal) Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring the decimal variable
Decimal a = 4.01m;
// finding the ceiling of
// the Decimal value
// using ceiling() method;
Decimal value = Decimal.Ceiling(a);
// Display the ceiling
Console.WriteLine("Ceiling Value is : {0}",
value);
}
}
输出:
Ceiling Value is : 5
范例2:
// C# program to demonstrate the
// Decimal.Ceiling(Decimal) Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring the decimal variable
Decimal a = -5.03m;
// finding the Ceiling of
// the Decimal value
// using Ceiling() method;
Decimal value = Decimal.Ceiling(a);
// Display the Ceiling
Console.WriteLine("Ceiling Value is : {0}",
value);
}
}
输出:
Ceiling Value is : -5
范例3:
// C# program to demonstrate the
// Decimal.Ceiling(Decimal) Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring the decimal variable
Decimal a = 2.00m;
// finding the Ceiling of
// the Decimal value
// using Ceiling() method;
Decimal value = Decimal.Ceiling(a);
// Display the Ceiling
Console.WriteLine("Ceiling Value is : {0}",
value);
}
}
输出:
Ceiling Value is : 2