Math.Floor() Method in C#


The Math.Floor() method in C# is used to return the largest integral value less than or equal to the specified number.

Syntax

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

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

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

Example

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

Output

This will produce the following output −

Result = 7
Result = -80

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

Example

using System;
public class Demo {
   public static void Main(){
      double val1 = 8.9;
      double val2 = 88.10;
      double val3 = -31.98;
      Console.WriteLine("Result = " + Math.Floor(val1));
      Console.WriteLine("Result = " + Math.Floor(val2));
      Console.WriteLine("Result = " + Math.Floor(val3));
   }
}

Output

This will produce the following output −

Result = 8
Result = 88
Result = -32

Updated on: 04-Nov-2019

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements