MathF.Floor() Method in C# with Examples


The MathF.Floor() method in C# is used to find the largest integer, which is less than or equal to the specified float value.

Syntax

Following is the syntax −

public static float Floor (float val);

Above, the Val is the floating-point value.

Example

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

using System;
class Demo {
   public static void Main(){
      float val = 45.67f;
      float res = MathF.Floor(val);
      Console.WriteLine("MathF.Floor() = "+res);
   }
}

Output

This will produce the following output −

MathF.Floor() = 45

Example

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

using System;
class Demo {
   public static void Main(){
      float val = -10.33f;
      float res = MathF.Floor(val);
      Console.WriteLine("MathF.Floor() = "+res);
   }
}

Output

This will produce the following output −

MathF.Floor() = -11

Updated on: 14-Nov-2019

68 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements