.Floor()

Published Feb 20, 2023Updated Mar 31, 2023
Contribute to Docs

Math.Floor() is a static method that rounds down and returns the largest whole integer that is less than or equal to the given number.

Syntax

Math.Floor(x);
  • The Math.Floor() method is used to find the largest whole integer that is less than or equal to the argument, x, passed in. The argument can be of a float or double type.
  • The System namespace is required to access this method.

Example

The following example uses Math.Floor() to return the largest whole number.

// Include the System namespace
using System;
public class Floor {
public static void Main() {
Console.WriteLine(Math.Floor(5.05));
}
}

The example will result in the following output:

5

Codebyte Example

The following example is runnable and uses the Math.Floor() method to return the largest whole number that is less than or equal to the given double type number:

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn C# on Codecademy