SelectDB Cloud
SQL 手册
SQL 函数
数学函数
FLOOR

floor

description

Syntax

BIGINT floor(DOUBLE x)

如果不指定d: 返回小于或等于x的最大整数值, 这也是最常见的用法. 否则, 按照下面规则返回最大的小于或者等于x的舍入数字:

d 是字面量(不是列):
d = 0: 等同于没有 d d > 0 or d < 0: 舍入数是 1/(10^d) 的倍数,如果 1/(10^d) 不精确,则为相应数据类型的最接近的数字。

如果 d 为一个列,并且第一个参数为 Decimal 类型,那么结果 Decimal 会跟入参 Decimal 具有相同的小数部分长度。

:::tip 该函数的另一个别名为 dfloor。 :::

example

mysql> select floor(1);
+------------+
| floor(1.0) |
+------------+
|          1 |
+------------+
mysql> select floor(2.4);
+------------+
| floor(2.4) |
+------------+
|          2 |
+------------+
mysql> select floor(-10.3);
+--------------+
| floor(-10.3) |
+--------------+
|          -11 |
+--------------+
mysql> 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 |
+------------------+---------------+------------------+-------------------+
mysql> SELECT number
    -> , floor(number * 2.5, number - 1) AS f_decimal_column
    -> , floor(number * 2.5, 0) AS f_decimal_literal
    -> , floor(cast(number * 2.5 AS DOUBLE), number - 1) AS f_double_column
    -> , floor(cast(number * 2.5 AS DOUBLE), 0) AS f_double_literal
    -> FROM test_enhanced_round
    -> WHERE rid = 1;
+--------+------------------+-------------------+-----------------+------------------+
| number | f_decimal_column | f_decimal_literal | f_double_column | f_double_literal |
+--------+------------------+-------------------+-----------------+------------------+
|      1 |              2.0 |                 2 |               2 |                2 |
+--------+------------------+-------------------+-----------------+------------------+

keywords

FLOOR, DFLOOR
© 2023 北京飞轮数据科技有限公司 京ICP备2022004029号 | Apache、Apache Doris 以及相关开源项目名称均为 Apache 基金会商标