The Wayback Machine - https://web.archive.org/web/20240214221141/https://www.geeksforgeeks.org/c-sharp-math-ceiling-method/
Open In App
Related Articles

C# | Math.Ceiling() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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

// C# program to illustrate the
// Math.Ceiling(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 Math.Ceiling() function
        decimal ceil_t1 = Math.Ceiling(decim_n1);
        decimal ceil_t2 = Math.Ceiling(decim_n2);
        decimal ceil_t3 = Math.Ceiling(decim_n3);
 
        // Print First values and Ceiling
        Console.WriteLine("Input Value  = " + decim_n1);
        Console.WriteLine("Ceiling value = " + ceil_t1);
 
        // Print Second values and Ceiling
        Console.WriteLine("Input Value  = " + decim_n2);
        Console.WriteLine("Ceiling value = " + ceil_t2);
 
        // Print third values and Ceiling
        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

// C# program to illustrate the
// Math.Ceiling(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 Math.Ceiling() function
        double t1 = Math.Ceiling(n1);
        double t2 = Math.Ceiling(n2);
        double t3 = Math.Ceiling(n3);
 
        // Print First values and Ceiling
        Console.WriteLine("Input Value  = " + n1);
        Console.WriteLine("Ceiling value = " + t1);
 
        // Print Second values and Ceiling
        Console.WriteLine("Input Value  = " + n2);
        Console.WriteLine("Ceiling value = " + t2);
 
        // Print third values and Ceiling
        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: 
 


 


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Looking for a place to share your ideas, learn, and connect? Our Community portal is just the spot! Come join us and see what all the buzz is about!


Last Updated : 16 Sep, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads