Math.Ceiling() Method in C#


The Math.Ceiling() method in C# is used to return the smallest integral value greater than or equal to the specified number.

Syntax

Following is the syntax −

public static decimal Ceiling (decimal val);
public static double Ceiling(double val)

For the first syntax above, the value Val is the decimal number, whereas Val in the second syntax is the double number.

Example

Let us now see an example to implement Math.Ceiling() method −

using System;
public class Demo {
   public static void Main(){
      decimal val1 = 9.99M;
      decimal val2 = -5.10M;
      Console.WriteLine("Result = " + Math.Ceiling(val1));
      Console.WriteLine("Result = " + Math.Ceiling(val2));
   }
}

Output

This will produce the following output −

Result = 10
Result = -5

Example

Let us see another example to implement Math.Ceiling() method −

using System;
public class Demo {
   public static void Main(){
      double val1 = 3.1;
      double val2 = 55.99;
      double val3 = -55.99;
      Console.WriteLine("Result = " + Math.Ceiling(val1));
      Console.WriteLine("Result = " + Math.Ceiling(val2));
      Console.WriteLine("Result = " + Math.Ceiling(val3));
   }
}

Output

This will produce the following output −

Result = 4
Result = 56
Result = -55

Updated on: 08-Nov-2019

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements