The ROUND function in MySQL is used to round numbers. The syntax is ROUND(number, decimal_places), where number is the number to be rounded, and decimal_places is the number of decimal places retained after rounding, such as ROUND( 123.456, 2) Returns the number 123.46 rounded to two decimal places.
ROUND Function in MySQL
ROUND function is a function used to round numbers. It takes two parameters:
Syntax:
<code class="mysql">ROUND(number, decimal_places)</code>
Return value:
ROUND function returns the rounded number.
Usage:
ROUND function is often used to format currency values or other numbers that need to be rounded. For example:
<code class="mysql">SELECT ROUND(123.456, 2);</code>
This will return the number rounded to two decimal places: 123.46.
Example:
The following table shows the ROUND function results for different numbers and decimal places:
Number | Decimal places | Result |
---|---|---|
0 | 123 | |
1 | 123.5 | |
2 | 123.46 | |
3 | 123.456 |
If the number of decimal places is negative, the ROUND function will round to integer digits.
The above is the detailed content of What is the round function in mysql?. For more information, please follow other related articles on the PHP Chinese website!