Decimal.Floor(Decimal) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將指定 Decimal 數字四捨五入為最接近負無限大的整數。
public:
static System::Decimal Floor(System::Decimal d);
public:
static System::Decimal Floor(System::Decimal d) = System::Numerics::IFloatingPoint<System::Decimal>::Floor;
public static decimal Floor(decimal d);
static member Floor : decimal -> decimal
Public Shared Function Floor (d As Decimal) As Decimal
參數
- d
- Decimal
要捨入的值。
傳回
若 d 有分數部分,則下一個小於 的整 Decimal 數趨向負無限 d大。
-或-
若 d 沒有分數部分, d 則未改變地返回。 請注意,該方法回傳一個型別 Decimal為 的整數值。
實作
範例
以下範例說明此 Floor 方法並與該 Ceiling 方法作對比。
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
open System
let values =
[ 12.6m; 12.1m; 9.5m; 8.16m; 0.1m; -0.1m; -1.1m; -1.9m; -3.9m ]
printfn "%-8s %10s %10s\n" "Value" "Ceiling" "Floor"
for value in values do
printfn $"%-8O{value} %10O{Decimal.Ceiling value} %10O{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
Module Example
Public Sub Main()
Dim values() As Decimal = {12.6d, 12.1d, 9.5d, 8.16d, .1d, -.1d,
-1.1d, -1.9d, -3.9d}
Console.WriteLine("{0,-8} {1,10} {2,10}",
"Value", "Ceiling", "Floor")
Console.WriteLine()
For Each value As Decimal In values
Console.WriteLine("{0,-8} {1,10} {2,10}", value,
Decimal.Ceiling(value), Decimal.Floor(value))
Next
End Sub
End Module
' 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
備註
此方法的行為遵循 IEEE 標準 754,第 4 節。 這種四捨五入有時稱為向負無限四捨五入。 換句話說,若 d 為正,任何分數分量都會被截斷。 若 d 為負,任何分數分量的存在會使其被四捨五入為較小的整數。 此方法的運作方式與支持將正無限大捨入的方法不同 Ceiling 。