truncate

description

Syntax

DOUBLE truncate(DOUBLE x, INT d) Numerically truncate x according to the number of decimal places d.

The rules are as follows: When d > 0: keep d decimal places of x When d = 0: remove the fractional part of x and keep only the integer part When d < 0: Remove the fractional part of x, and replace the integer part with the number 0 according to the number of digits specified by d

example

  1. mysql> select truncate(124.3867, 2);
  2. +-----------------------+
  3. | truncate(124.3867, 2) |
  4. +-----------------------+
  5. | 124.38 |
  6. +-----------------------+
  7. mysql> select truncate(124.3867, 0);
  8. +-----------------------+
  9. | truncate(124.3867, 0) |
  10. +-----------------------+
  11. | 124 |
  12. +-----------------------+
  13. mysql> select truncate(-124.3867, -2);
  14. +-------------------------+
  15. | truncate(-124.3867, -2) |
  16. +-------------------------+
  17. | -100 |
  18. +-------------------------+

keywords

  1. TRUNCATE