Latest web development tutorials

SQL ROUND () function

ROUND () function

ROUND () function for the numeric field rounded to the specified number of decimal places.

SQL ROUND () syntax

SELECT ROUND(column_name,decimals) FROM table_name;

参数 描述
column_name 必需。要舍入的字段。
decimals 必需。规定要返回的小数位数。

SQL ROUND () examples

ROUND (X): returns an integer parameter X rounded.

mysql> select ROUND(-1.23);
        -> -1
mysql> select ROUND(-1.58);
        -> -2
mysql> select ROUND(1.58);
        -> 2

ROUND (X, D): Returns the parameter X has rounded D is a decimal digit. If D is 0, the result will have no decimal point or fractional part.

mysql> select ROUND(1.298, 1);
        -> 1.3
mysql> select ROUND(1.298, 0);
        -> 1

NOTE: ROUND return value is converted to a BIGINT!