Decimal.Ceiling(Decimal) メソッド

定義

指定した 10 進数以上の数のうち、最小の整数値を返します。

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

10 進数。

戻り値

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
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 に従います。 このような丸めは、正の無限大に向かって丸めと呼ばれる場合があります。 つまり、 が正の場合、小数部が存在すると、次に高い整数 d d に丸められます。 が d 負の場合、丸め操作によって の小数部 d が破棄されます。 このメソッドの操作は、負の無限大への丸め処理をサポートする メソッド Floor とは異なります。

適用対象

こちらもご覧ください