ceil

description

Syntax

T ceil(T x[, d])

If not specified d: returns the smallest integer value less than or equal to x, which is the most common usage. Otherwise, returns the smallest 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.

CEIL - 图1tip

The other alias for this function are dceil and ceiling.

example

  1. mysql> select ceil(1);
  2. +-----------+
  3. | ceil(1.0) |
  4. +-----------+
  5. | 1 |
  6. +-----------+
  7. mysql> select ceil(2.4);
  8. +-----------+
  9. | ceil(2.4) |
  10. +-----------+
  11. | 3 |
  12. +-----------+
  13. mysql> select ceil(-10.3);
  14. +-------------+
  15. | ceil(-10.3) |
  16. +-------------+
  17. | -10 |
  18. +-------------+
  19. mysql> select ceil(123.45, 1), ceil(123.45), ceil(123.45, 0), ceil(123.45, -1);
  20. +-----------------+--------------+-----------------+------------------+
  21. | ceil(123.45, 1) | ceil(123.45) | ceil(123.45, 0) | ceil(123.45, -1) |
  22. +-----------------+--------------+-----------------+------------------+
  23. | 123.5 | 124 | 124 | 130 |
  24. +-----------------+--------------+-----------------+------------------+
  25. mysql> SELECT number
  26. -> , ceil(number * 2.5, number - 1) AS c_decimal_column
  27. -> , ceil(number * 2.5, 0) AS c_decimal_literal
  28. -> , ceil(cast(number * 2.5 AS DOUBLE), number - 1) AS c_double_column
  29. -> , ceil(cast(number * 2.5 AS DOUBLE), 0) AS c_double_literal
  30. -> FROM test_enhanced_round
  31. -> WHERE rid = 1;
  32. +--------+------------------+-------------------+-----------------+------------------+
  33. | number | c_decimal_column | c_decimal_literal | c_double_column | c_double_literal |
  34. +--------+------------------+-------------------+-----------------+------------------+
  35. | 1 | 3.0 | 3 | 3 | 3 |
  36. +--------+------------------+-------------------+-----------------+------------------+

keywords

  1. CEIL, DCEIL, CEILING