In C#, Math.Ceiling() is a Math class method. This method is used to find the smallest integer , which is greater than or equal to the passed argument. The Ceiling method operates both functionalities in decimal and double. This method can be overload by passing different arguments to it.
- Math.Ceiling(Decimal) Method
- Math.Ceiling(Double) Method
Math.Ceiling(Decimal) Method
This method is used to returns the smallest integral value which is greater than or equal to the specified decimal number in the argument list.
Syntax:
public static decimal Ceiling(decimal d)
Parameter:
Decimal d: It is the decimal number of type System.Decimal.
Return Type: This function return the smallest integral value which will be greater than or equal to d. The type of this method is System.Decimal and return a decimal instead of an integral type.
Examples:
Input : 888.765M;
Output : 889
Input : -20002.999M
Output : -20002
Program : To demonstrate the Math.Ceiling(Decimal) method.
CSHARP
using System;
class SudoPlacement {
static void Main()
{
decimal decim_n1 = 2.10M;
decimal decim_n2 = -99.90M;
decimal decim_n3 = 33.001M;
decimal ceil_t1 = Math.Ceiling(decim_n1);
decimal ceil_t2 = Math.Ceiling(decim_n2);
decimal ceil_t3 = Math.Ceiling(decim_n3);
Console.WriteLine( "Input Value = " + decim_n1);
Console.WriteLine( "Ceiling value = " + ceil_t1);
Console.WriteLine( "Input Value = " + decim_n2);
Console.WriteLine( "Ceiling value = " + ceil_t2);
Console.WriteLine( "Input Value = " + decim_n3);
Console.WriteLine( "Ceiling value = " + ceil_t3);
}
}
|
Output: Input Value = 2.10
Ceiling value = 3
Input Value = -99.90
Ceiling value = -99
Input Value = 33.001
Ceiling value = 34
Math.Ceiling(Double) Method
This method is used to returns the smallest integral value which is greater than or equal to the specified double-precision floating-point number in the argument list.
Syntax:
public static double Ceiling(double d)
Parameter:
Double d: It is the double number of type System.Double.
Return Type: This method returns the smallest integral value that is greater than or equal to d. If d is equal to NaN, NegativeInfinity, or PositiveInfinity, that value is returned. The type of this method is System.Double.
Examples:
Input : 10.1
Output : 11
Input : -2222.2220
Output : -2222
Program : To demonstrate the Math.Ceiling(Double) method.
CSHARP
using System;
class SudoPlacement {
static void Main()
{
double n1 = 101.10;
double n2 = -1.1;
double n3 = 9222.1000;
double t1 = Math.Ceiling(n1);
double t2 = Math.Ceiling(n2);
double t3 = Math.Ceiling(n3);
Console.WriteLine( "Input Value = " + n1);
Console.WriteLine( "Ceiling value = " + t1);
Console.WriteLine( "Input Value = " + n2);
Console.WriteLine( "Ceiling value = " + t2);
Console.WriteLine( "Input Value = " + n3);
Console.WriteLine( "Ceiling value = " + t3);
}
}
|
Output: Input Value = 101.1
Ceiling value = 102
Input Value = -1.1
Ceiling value = -1
Input Value = 9222.1
Ceiling value = 9223
References: