FLOOR
説明
浮動小数点数および固定小数点数を指定した桁数に切り下げ、丸められた浮動小数点数または固定小数点数を返します。
構文
FLOOR(<a>[, <d>])
パラメータ
| Parameter | デスクリプション |
|---|---|
<a> | 丸め対象のパラメータを示す浮動小数点(Double)または固定小数点(Decimal)パラメータ |
<d> | オプション、整数、目標桁数への丸めを示す。正の数は次の小数点への丸めを意味し、負の数は次の小数点への丸めを意味し、0は整数への丸めを示す。未入力の場合、<d> = 0と同等。 |
Return Value
以下のルールに従って、<a>以下の最大の丸められた数値を返す。
1/(10^d)桁に丸める、つまり結果を1/(10^d)で割り切れるようにする。1/(10^d)が正確でない場合、丸め桁は対応するデータ型の最も近い数値となる。
Decimal(p, s)型のDecimal型のエントリ<a>に対して、戻り値は以下のとおり:
Decimal(p, 0)、<d> <= 0の場合Decimal(p, <d>)、0 < <d> <= sの場合Decimal(p, s)、<d> > sの場合
Alias
- DFLOOR
Examples
select floor(123.456);
+----------------+
| floor(123.456) |
+----------------+
| 123 |
+----------------+
select floor(123.456, 2);
+-------------------+
| floor(123.456, 2) |
+-------------------+
| 123.45 |
+-------------------+
select floor(123.456, -2);
+--------------------+
| floor(123.456, -2) |
+--------------------+
| 100 |
+--------------------+
select floor(123.45, 1), floor(123.45), floor(123.45, 0), floor(123.45, -1);
+------------------+---------------+------------------+-------------------+
| floor(123.45, 1) | floor(123.45) | floor(123.45, 0) | floor(123.45, -1) |
+------------------+---------------+------------------+-------------------+
| 123.4 | 123 | 123 | 120 |
+------------------+---------------+------------------+-------------------+
select floor(x, 2) from ( select cast(123.456 as decimal(6,3)) as x from numbers("number"="5") )t;
+-------------+
| floor(x, 2) |
+-------------+
| 123.45 |
| 123.45 |
| 123.45 |
| 123.45 |
| 123.45 |
+-------------+