メインコンテンツまでスキップ
バージョン: 2.1

CEIL

説明

浮動小数点数と固定小数点数の小数を指定した桁数に切り上げ、切り上げられた浮動小数点数または固定小数点数を返します。

構文

CEIL(<a>[, <d>])

パラメータ

Parameterデスクリプション
<a>丸める対象のパラメータを示す浮動小数点(Double)または固定小数点(Decimal)パラメータ
<d>省略可能、整数、対象桁数への丸めを示す。正の数は次の小数点への丸め、負の数は次の小数点への丸め、0は整数への丸めを示す。未入力の場合、<d> = 0と同等。

Return Value

以下のルールに従って、<a>以上の最小の丸められた数値を返します。

1/(10^d)桁に丸める、つまり結果を1/(10^d)で割り切れるようにします。1/(10^d)が正確でない場合、丸める桁は対応するデータ型の最も近い数値になります。

Decimal型のエントリ<a>について、それがDecimal(p, s)型であると仮定すると、戻り値は以下のようになります:

  • Decimal(p, 0)<d> <= 0の場合
  • Decimal(p, <d>)0 < <d> <= sの場合
  • Decimal(p, s)<d> > sの場合

Alias

  • DCEIL
  • CEILING

Examples

select ceil(123.456);
+---------------+
| ceil(123.456) |
+---------------+
| 124 |
+---------------+
select ceil(123.456, 2);
+------------------+
| ceil(123.456, 2) |
+------------------+
| 123.46 |
+------------------+
select ceil(123.456, -2);
+-------------------+
| ceil(123.456, -2) |
+-------------------+
| 200 |
+-------------------+
select ceil(123.45, 1), ceil(123.45), ceil(123.45, 0), ceil(123.45, -1);
+-----------------+--------------+-----------------+------------------+
| ceil(123.45, 1) | ceil(123.45) | ceil(123.45, 0) | ceil(123.45, -1) |
+-----------------+--------------+-----------------+------------------+
| 123.5 | 124 | 124 | 130 |
+-----------------+--------------+-----------------+------------------+
select ceil(x, 2) from ( select cast(123.456 as decimal(6,3)) as x from numbers("number"="5") )t;
+------------+
| ceil(x, 2) |
+------------+
| 123.46 |
| 123.46 |
| 123.46 |
| 123.46 |
| 123.46 |
+------------+