floor

description

Syntax

T floor(T x[, d])

If not specified d: returns the largest integer value less than or equal to x, which is the most common usage. Otherwise, returns the largest round number that is less than or equal to x and flowing the rules:

If d is specified as literal:
d = 0: just like without d d > 0 or d < 0: the round number would be a multiple of 1/(10^d), or the nearest number of the appropriate data type if 1/(10^d) isn’t exact.

Else if d is a column, and x has Decimal type, scale of result Decimal will always be same with input Decimal.

FLOOR - 图1tip

Another alias for this function is dfloor.

example

  1. mysql> select floor(1);
  2. +------------+
  3. | floor(1.0) |
  4. +------------+
  5. | 1 |
  6. +------------+
  7. mysql> select floor(2.4);
  8. +------------+
  9. | floor(2.4) |
  10. +------------+
  11. | 2 |
  12. +------------+
  13. mysql> select floor(-10.3);
  14. +--------------+
  15. | floor(-10.3) |
  16. +--------------+
  17. | -11 |
  18. +--------------+
  19. mysql> select floor(123.45, 1), floor(123.45), floor(123.45, 0), floor(123.45, -1);
  20. +------------------+---------------+------------------+-------------------+
  21. | floor(123.45, 1) | floor(123.45) | floor(123.45, 0) | floor(123.45, -1) |
  22. +------------------+---------------+------------------+-------------------+
  23. | 123.4 | 123 | 123 | 120 |
  24. +------------------+---------------+------------------+-------------------+
  25. mysql> SELECT number
  26. -> , floor(number * 2.5, number - 1) AS f_decimal_column
  27. -> , floor(number * 2.5, 0) AS f_decimal_literal
  28. -> , floor(cast(number * 2.5 AS DOUBLE), number - 1) AS f_double_column
  29. -> , floor(cast(number * 2.5 AS DOUBLE), 0) AS f_double_literal
  30. -> FROM test_enhanced_round
  31. -> WHERE rid = 1;
  32. +--------+------------------+-------------------+-----------------+------------------+
  33. | number | f_decimal_column | f_decimal_literal | f_double_column | f_double_literal |
  34. +--------+------------------+-------------------+-----------------+------------------+
  35. | 1 | 2.0 | 2 | 2 | 2 |
  36. +--------+------------------+-------------------+-----------------+------------------+

keywords

  1. FLOOR, DFLOOR