In this guide, we will explain how to use the MySQL ROUND function with syntax and examples.
Description
The MySQL ROUND function returns a number rounded to a certain number of decimal places.
Syntax
The syntax for the ROUND function in MySQL is:
ROUND( number, [ decimal_places ] )
Parameters or Arguments
number
The number to round.
decimal_places
The number of decimal places to round. This value must be a positive or negative integer. If this parameter is omitted, the ROUND function will round the number to 0 decimal places.
Note
- If decimal_places is a negative number, the ROUND function will make digits to the left of the decimal place 0 values.
- The behavior of the ROUND function can vary depending on the version of MySQL.
- See also the FLOOR, CEIL, CEILING, and TRUNCATE functions.
Applies To
The ROUND function can be used in the following versions :
- MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23
Example
Let’s look at some ROUND function examples and explore how to use the ROUND function.
For example:
mysql> SELECT ROUND(125.315); Result: 125 mysql> SELECT ROUND(125.315, 0); Result: 125 mysql> SELECT ROUND(125.315, 1); Result: 125.3 mysql> SELECT ROUND(125.315, 2); Result: 125.32 mysql> SELECT ROUND(125.315, -1); Result: 130 mysql> SELECT ROUND(125.315, -2); Result: 100 mysql> SELECT ROUND(-125.315); Result: -125
Next Topic : Click Here
Pingback: MySQL: RAND Function | Adglob Infosystem Pvt Ltd