Decimal.Ceiling(Decimal) Decimal.Ceiling(Decimal) Decimal.Ceiling(Decimal) Decimal.Ceiling(Decimal) Method

定義

傳回大於或等於指定之十進位數字的最小整數值。Returns the smallest integral value that is greater than or equal to the specified decimal number.

public:
 static System::Decimal Ceiling(System::Decimal d);
public static decimal Ceiling (decimal d);
static member Ceiling : decimal -> decimal
Public Shared Function Ceiling (d As Decimal) As Decimal

參數

d
Decimal Decimal Decimal Decimal

十進位數字。A decimal number.

傳回

大於或等於 d 參數的最小整數值。The smallest integral value that is greater than or equal to the d parameter. 請注意,這個方法會傳回 Decimal,而不是整數類型。Note that this method returns a Decimal instead of an integral type.

範例

下列範例說明Ceiling方法,並將它Floor與方法做比較。The following example illustrates the Ceiling method and contrasts it with the Floor 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
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 Standard 754,第4節。The behavior of this method follows IEEE Standard 754, section 4. 這種舍入有時稱為正無限大的舍入。This kind of rounding is sometimes called rounding toward positive infinity. 換句話說,如果d是正數,任何小陣列件的存在都會導致d四捨五入成下一個最大整數。In other words, if d is positive, the presence of any fractional component causes d to be rounded to the next highest integer. 如果d是負數,舍入運算會導致捨棄的d任何小數部分。If d is negative, the rounding operation causes any fractional component of d to be discarded. 這個方法的作業與Floor方法不同,它支援向負無限大進行舍入。The operation of this method differs from the Floor method, which supports rounding toward negative infinity.

適用於

另請參閱