SelectDB Enterprise
参考手册
SQL 函数
标量函数
数值函数
FLOOR

FLOOR

描述

对浮点及定点小数按特定位数向下取整,返回取整过后的浮点或定点数。

语法

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

参数

参数说明
<a>浮点 (Double) 或定点 (Decimal) 参数,表示要进行取整的参数
<d>可选的,整数,表示舍入目标位数,正数为向小数点后舍入,负数为向小数点前舍入,0 表示舍入到整数。不填写时等同于 <d> = 0

返回值

按照下面规则返回最大的小于或者等于 <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

别名

  • DFLOOR

举例

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 |
+-------------+
© 2025 北京飞轮数据科技有限公司 京ICP备2022004029号 | Apache、Apache Doris 以及相关开源项目名称均为 Apache 基金会商标