SQL ROUND()
SQL ROUND() Function
ROUND() Function
ROUND() function is used to round numeric fields for the specified number of decimal places.
SQL ROUND() syntax
SELECT ROUND(column_name,decimals) FROM table_name;
Parameters | Description |
---|---|
column_name | Required. The field to round. |
decimals | Required. Specifies the number of decimal places to be returned. |
SQL ROUND() Example
ROUND(X):Return A rounded integer for parameter X.
mysql> select ROUND(-1.23);
- -> -1
mysql> select ROUND(-1.58);
-> -2
mysql> ; select ROUND(1.58);
-> 2
- -> -1
mysql> select ROUND(-1.58);
-> -2
mysql> ; select ROUND(1.58);
-> 2
ROUND(X,D): Returns the rounded number of parameter X with D as a decimal. If D is 0, the result will have no decimal point or decimal part.
mysql> select ROUND(1.298, 1);
--> 1.3
mysql> select ROUND(1.298, 0);
--> 1
--> 1.3
mysql> select ROUND(1.298, 0);
--> 1
Note: The return value of ROUND is converted into a BIGINT!