SQL ROUND function is used to round a number to the right of the decimal point for positive values and to the left of the decimal point for negative values. When used, specify the number and digits to be rounded. For example, ROUND(123.456, 2) will round to two digits to the right of the decimal point, and the result is 123.46.
Usage of ROUND function in SQL
Introduction to ROUND function
## The #ROUND function rounds a number and rounds the result to a specified number of digits.Syntax
<code>ROUND(number, decimals)</code>Where:
: The number to be rounded.
: Number of digits to round. Positive values represent the number of digits to the right of the decimal point, and negative values represent the number of digits to the left of the decimal point.
How to use
To round a number, use the following steps:Example
Round to two digits to the right of the decimal point
<code>SELECT ROUND(123.456, 2);</code>Result: 123.46
Round to the nearest whole number to the left of the decimal point
<code>SELECT ROUND(123456, -2);</code>Result: 123000
Notes
is zero, the function rounds the number to the nearest integer.
is positive, the function rounds the number to the specified number of digits to the right of the decimal point.
is negative, the function rounds the number to the specified number of digits to the left of the decimal point.
is NULL, the function returns NULL.
The above is the detailed content of How to use round in sql. For more information, please follow other related articles on the PHP Chinese website!