Decimal.Ceiling() Method in C#

This method is used to round the decimal to the closest integer toward positive infinity.

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.

Below programs illustrate the use of Decimal.Ceiling(Decimal) Method:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Output:

Ceiling Value is : 5

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Output:

Ceiling Value is : -5

Example 3:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Output:

Ceiling Value is : 2


My Personal Notes arrow_drop_up

Budding Web DeveloperKeen learnerAverage CoderDancer&Social Activist

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.