C# .Floor()

cslylla's avatar
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.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn Microsoft's popular C# programming language, used to make websites, mobile apps, video games, VR, and more.
    • Beginner Friendly.
      15 hours

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:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn C# on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn Microsoft's popular C# programming language, used to make websites, mobile apps, video games, VR, and more.
    • Beginner Friendly.
      15 hours