MathF.Ceiling() Method in C# with Examples


The MathF.Ceiling() method in C# is used to find the smallest integer greater than or equal to the float value in the argument.

Syntax

Following is the syntax −

public static float Ceiling (float val);

Above, Val is the floating-point value.

Example

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

using System;
class Demo {
   public static void Main(){
      float val1 = 12.67f;
      float val2 = 30.13f;
      Console.WriteLine("Ceiling (value1) = "+MathF.Ceiling(val1));
      Console.WriteLine("Ceiling (value2) = "+MathF.Ceiling(val2));
   }
}

Output

This will produce the following output −

Ceiling (value1) = 13
Ceiling (value2) = 31

Example

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

using System;
class Demo {
   public static void Main(){
      float val1 = 01.11f;
      float val2 = -30.99f;
      Console.WriteLine("Ceiling (value1) = "+MathF.Ceiling(val1));
      Console.WriteLine("Ceiling (value2) = "+MathF.Ceiling(val2));
   }
}

Output

This will produce the following output −

Ceiling (value1) = 2
Ceiling (value2) = -30

Updated on: 13-Nov-2019

187 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements