Facebook Page Twitter Page LinkedIn Page
× C# Tutorial C# Advanced C# Resources


The C# Math Floor() method is used to return the next lowest integer value by rounding down the specified number, if necessary. In other words, it rounds the fraction DOWN of the given number. The method can be overloaded and it can take decimal and double arguments. In special cases it returns the following:

  • If the argument value is already an integer, the method returns the same as the argument.
  • If the argument is NaN or PositiveInfinity or NegativeInfinity, the method returns the same as the argument.

Syntax

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

Parameters

arg Specify a number.

Return Value

Returns the next lowest integer value by rounding DOWN the specified number, if necessary.

Example:

In the below example, Floor() method is used to round the fraction DOWN of the specified number.

using System;

class MyProgram {
  static void Main(string[] args) {
	 Console.WriteLine(Math.Floor(10.5)); 
	 Console.WriteLine(Math.Floor(-10.5));
	 Console.WriteLine(Math.Floor(0.5)); 
	 Console.WriteLine(Math.Floor(-0.5)); 
  }
}

The output of the above code will be:

10
-11
0
-1

❮ C# Math Methods