Decimal.Ceiling() Method in C#


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

Syntax

Following is the syntax −

public static decimal Ceiling (decimal val);

Above, Val is the decimal number.

Example

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

using System;
public class Demo {
   public static void Main(){
      Decimal val1 = 12.85m;
      Decimal val2 = 3.45m;
      Console.WriteLine("Decimal 1 = "+val1);
      Console.WriteLine("Decimal 2 = "+val2);
      Console.WriteLine("Ceiling (val1) = "+Decimal.Ceiling(val1));
      Console.WriteLine("Ceiling (val2) = "+Decimal.Ceiling(val2));
   }
}

Output

This will produce the following output −

Decimal 1 = 12.85
Decimal 2 = 3.45
Ceiling (val1) = 13
Ceiling (val2) = 4

Example

Let us now see another example to implement the Decimal.Ceiling() method −

using System;
public class Demo {
   public static void Main(){
      Decimal val1 = -10.85m;
      Decimal val2 = -33.45m;
      Console.WriteLine("Decimal 1 = "+val1);
      Console.WriteLine("Decimal 2 = "+val2);
      Console.WriteLine("Ceiling (val1) = "+Decimal.Ceiling(val1));
      Console.WriteLine("Ceiling (val2) = "+Decimal.Ceiling(val2));
   }
}

Output

This will produce the following output −

Decimal 1 = -10.85
Decimal 2 = -33.45
Ceiling (val1) = -10
Ceiling (val2) = -33

Updated on: 12-Nov-2019

321 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements