此方法用於將小數點四舍五入為負無窮大的最接近的整數。
用法: public static decimal Floor (decimal d);
參數:
d:此參數指定要四舍五入的小數。
返回值:如果d具有小數部分,則小於d或d的負整數的下一個整數十進製數沒有小數部分,則d不變地返回。請注意,該方法返回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
相關用法
- C# Queue.Contains()用法及代碼示例
- C# Math.Log()用法及代碼示例
- C# Uri.ToString()用法及代碼示例
- C# Random.Next()用法及代碼示例
- C# DateTimeOffset.Add()用法及代碼示例
- C# Uri.IsWellFormedOriginalString()用法及代碼示例
注:本文由純淨天空篩選整理自IshwarGupta大神的英文原創作品 Decimal.Floor() Method in C#。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。