此方法用于将小数点四舍五入为负无穷大的最接近的整数。
Syntax: public static decimal Floor (decimal d);
Parameter:
d: This parameter specifies the decimal which will be rounded off.
Return Value: If d has a fractional part, the next whole Decimal number toward negative infinity that is less than d or d doesn’t have a fractional part, d is returned unchanged. Note that the method returns an integral value of type Decimal.
下面的程序说明了Decimal.Floor(Decimal)方法的用法:
范例1:
// C# program to demonstrate the
// Decimal.Floor(Decimal) Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring the decimal variable
Decimal a = 4.01m;
// finding the floor of the Decimal value
// using floor() method;
Decimal value = Decimal.Floor(a);
// Display the Floor
Console.WriteLine("Floor Value is : {0}",
value);
}
}
输出:
Floor Value is : 4
范例2:
// C# program to demonstrate the
// Decimal.Floor(Decimal) Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring the decimal variable
Decimal a = -5.03m;
// finding the floor of the Decimal value
// using floor() method;
Decimal value = Decimal.Floor(a);
// Display the Floor
Console.WriteLine("Floor Value is : {0}",
value);
}
}
输出:
Floor Value is : -6
范例3:
// C# program to demonstrate the
// Decimal.Floor(Decimal) Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring the decimal variable
Decimal a = 2.00m;
// finding the floor of
// the Decimal value
// using floor() method;
Decimal value = Decimal.Floor(a);
// Display the Floor
Console.WriteLine("Floor Value is : {0}",
value);
}
}
输出:
Floor Value is : 2