SQL Getting Sta...login
SQL Getting Started Tutorial Manual
author:php.cn  update time:2022-04-12 14:15:40

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;

ParametersDescription
column_nameRequired. The field to round.
decimalsRequired. 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

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

Note: The return value of ROUND is converted into a BIGINT!

php.cn