This documentation is archived and is not being maintained.

Decimal.Floor Method

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

[Visual Basic]
Public Shared Function Floor( _
   ByVal d As Decimal _
) As Decimal
[C#]
public static decimal Floor(
 decimal d
);
[C++]
public: static Decimal Floor(
 Decimal d
);
[JScript]
public static function Floor(
   d : Decimal
) : Decimal;

Parameters

d
A Decimal.

Return Value

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.

Example

The following code sample illustrates the use of Floor.

[Visual Basic] 
Class PiggyBank
    Public ReadOnly Property Dollars() As Decimal
        Get
            Return [Decimal].Floor(MyFortune)
        End Get
    End Property

    Protected MyFortune As Decimal

    Public Sub AddPenny()
        MyFortune += 0.01D
    End Sub
End Class

[C#] 
class PiggyBank {
    public decimal Dollars {
        get {
            return Decimal.Floor(MyFortune);
        }
    }

    protected decimal MyFortune;

    public void AddPenny() {
        MyFortune += .01m;
    }
}

[C++] 
public __gc class PiggyBank {
public:
    Decimal Dollars() {
        return Decimal::Floor(MyFortune);
    }

    void AddPenny() {
        Decimal::op_Addition(MyFortune, .01);
    }

protected:
    Decimal MyFortune;
};

[JScript] 
class PiggyBank {
    public function get Dollars() : Decimal {
        return Decimal.Floor(MyFortune);
    }

    protected var MyFortune : Decimal;

    public function AddPenny() {
        MyFortune = Decimal.Add(MyFortune, 0.01);
    }
}

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Decimal Structure | Decimal Members | System Namespace | Round | Truncate

Show: