Decimal.Ceiling(Decimal) 方法

定义

返回大于或等于指定十进制数的最小整型值。

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

参数

d
Decimal

十进制数。

返回

大于或等于 d 参数的最小整型值。 请注意,此方法返回一个 Decimal 而不是整型类型。

实现

示例

下面的示例演示了该方法 Ceiling ,并将其与 Floor 该方法进行对比。

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 舍入到下一个最高整数。 如果 d 为负数,舍入运算会导致放弃任何小数部分 d 。 此方法的操作不同于 Floor 支持向负无穷大舍入的方法。

适用于

另请参阅