ROUND()

Description

The ROUND() function rounds a number to a specified number of decimal places.
The function returns the nearest number of the specified order. In case when given number has equal distance to surrounding numbers, the function uses banker’s rounding for float number types and rounds away from zero for the other number types (Decimal).

Syntax

  1. > ROUND(number, decimals)
  2. > ROUND(number)

Arguments

ArgumentsDescription
numberRequired. The number to round, including any numeric data type supported now.
decimalsOptional. An integer that represents the number of decimal places you want to round to. Default value is 0.
decimals>0 then the function rounds the value to the right of the decimal point.
decimals<0 then the function rounds the value to the left of the decimal point.
decimals=0 then the function rounds the value to integer.

Examples

  1. > drop table if exists t1;
  2. > create table t1(a int ,b float);
  3. > insert into t1 values(1,0.5);
  4. > insert into t1 values(2,0.499);
  5. > insert into t1 values(3,0.501);
  6. > insert into t1 values(4,20.5);
  7. > insert into t1 values(5,20.499);
  8. > insert into t1 values(6,13.500);
  9. > insert into t1 values(7,-0.500);
  10. > insert into t1 values(8,-0.499);
  11. > insert into t1 values(9,-0.501);
  12. > insert into t1 values(10,-20.499);
  13. > insert into t1 values(11,-20.500);
  14. > insert into t1 values(12,-13.500);
  15. > select a,round(b) from t1;
  16. +------+----------+
  17. | a | round(b) |
  18. +------+----------+
  19. | 1 | 0.0000 |
  20. | 2 | 0.0000 |
  21. | 3 | 1.0000 |
  22. | 4 | 20.0000 |
  23. | 5 | 20.0000 |
  24. | 6 | 14.0000 |
  25. | 7 | -0.0000 |
  26. | 8 | -0.0000 |
  27. | 9 | -1.0000 |
  28. | 10 | -20.0000 |
  29. | 11 | -20.0000 |
  30. | 12 | -14.0000 |
  31. +------+----------+
  32. > select a,round(b,-1) from t1;
  33. +------+--------------+
  34. | a | round(b, -1) |
  35. +------+--------------+
  36. | 1 | 0.0000 |
  37. | 2 | 0.0000 |
  38. | 3 | 0.0000 |
  39. | 4 | 20.0000 |
  40. | 5 | 20.0000 |
  41. | 6 | 10.0000 |
  42. | 7 | -0.0000 |
  43. | 8 | -0.0000 |
  44. | 9 | -0.0000 |
  45. | 10 | -20.0000 |
  46. | 11 | -20.0000 |
  47. | 12 | -10.0000 |
  48. +------+--------------+
  49. > select round(a*b) from t1;
  50. +--------------+
  51. | round(a * b) |
  52. +--------------+
  53. | 0.0000 |
  54. | 1.0000 |
  55. | 2.0000 |
  56. | 82.0000 |
  57. | 102.0000 |
  58. | 81.0000 |
  59. | -4.0000 |
  60. | -4.0000 |
  61. | -5.0000 |
  62. | -205.0000 |
  63. | -226.0000 |
  64. | -162.0000 |
  65. +--------------+

Constraints

Currently, MatrixOne doesn’t support select function() without from tables.