Export (0) Print
Expand All

Decimal.Floor Method

Rounds a specified Decimal number to the closest integer toward negative infinity.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public static decimal Floor(
	decimal d
)

Parameters

d
Type: System.Decimal

The value to round.

Return Value

Type: System.Decimal
If d has a fractional part, the next whole Decimal number toward negative infinity that is less than d.
-or-
If d doesn't have a fractional part, d is returned unchanged. Note that the method returns an integral value of type Decimal.

The behavior of this method follows IEEE Standard 754, Section 4. This kind of rounding is sometimes called rounding toward negative infinity. In other words, if d is positive, any fractional component is truncated. If d is negative, the presence of any fractional component causes it to be rounded to the smaller integer. The operation of this method differs from the Ceiling method, which supports rounding toward positive infinity.

The following example illustrates the Floor method and contrasts it with the Ceiling method.

using System;

public class Example
{
   public static void Main()
   {
      decimal[] values = {12.6m, 12.1m, 9.5m, 8.16m, .1m, -.1m,  -1.1m, 
                          -1.9m, -3.9m};
      Console.WriteLine("{0,-8} {1,10} {2,10}\n", 
                        "Value", "Ceiling", "Floor");
      foreach (decimal value in values)
      Console.WriteLine("{0,-8} {1,10} {2,10}", value,
                        Decimal.Ceiling(value), Decimal.Floor(value));

   }
}
// The example displays the following output: 
//       Value       Ceiling      Floor 
//        
//       12.6             13         12 
//       12.1             13         12 
//       9.5              10          9 
//       8.16              9          8 
//       0.1               1          0 
//       -0.1              0         -1 
//       -1.1             -1         -2 
//       -1.9             -1         -2 
//       -3.9             -3         -4

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Show:
© 2015 Microsoft