round

description

Syntax

round(x), round(x, d)x四舍五入后保留d位小数,d默认为0。如果d为负数,则小数点左边d位为0。如果x或d为null,返回null。

example

  1. mysql> select round(2.4);
  2. +------------+
  3. | round(2.4) |
  4. +------------+
  5. | 2 |
  6. +------------+
  7. mysql> select round(2.5);
  8. +------------+
  9. | round(2.5) |
  10. +------------+
  11. | 3 |
  12. +------------+
  13. mysql> select round(-3.4);
  14. +-------------+
  15. | round(-3.4) |
  16. +-------------+
  17. | -3 |
  18. +-------------+
  19. mysql> select round(-3.5);
  20. +-------------+
  21. | round(-3.5) |
  22. +-------------+
  23. | -4 |
  24. +-------------+
  25. mysql> select round(1667.2725, 2);
  26. +---------------------+
  27. | round(1667.2725, 2) |
  28. +---------------------+
  29. | 1667.27 |
  30. +---------------------+
  31. mysql> select round(1667.2725, -2);
  32. +----------------------+
  33. | round(1667.2725, -2) |
  34. +----------------------+
  35. | 1700 |
  36. +----------------------+

keywords

  1. ROUND