SQL ROUND()Functions
ROUND() Function
The ROUND() function is used to round a numeric field to the specified number of decimal places.
SQL ROUND() Syntax
SELECT ROUND(column_name,decimals) FROM TABLE_NAME;
| Parameter | Description |
|---|---|
| column_name | Required. The field to be rounded. |
| decimals | Optional. Specifies the number of decimal places to return. |
SQL ROUND() Examples
ROUND(X):Returns an integer that is the rounded value of parameter X.
Example
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 a number rounded from parameter X with D decimal places. If D is 0, the result will have no decimal point or fractional part.
Example
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 ROUND return value is converted to a BIGINT!
Other Extensions