ROUND(number, decimals) rounds a numeric value. A negative decimals argument rounds to places left of the decimal point.
Run this SELECT query directly in MySQL or phpMyAdmin. It uses fixed inputs so you can verify the result without creating a table.
SELECT ROUND(12.345, 2) AS rounded_value;| rounded_value |
|---|
| 12.35 |
SELECT ROUND(4.589, 3); -- 4.589
SELECT ROUND(4.589, 4); -- 4.5890
SELECT ROUND(4.589, 2); -- 4.59
SELECT ROUND(4.589, 1); -- 4.6
SELECT ROUND(4.589); -- 5
SELECT ROUND(-4.589); -- -5
SELECT ROUND(-4.389); -- -4
Syntax
ROUND(X, D) -- X: number, D: decimal places
SELECT ROUND(14.729, 2); -- 14.73
Using negative value for Number of decimal places.
SELECT ROUND(234.96, -1); -- 230
SELECT ROUND(236.96, -1); -- 240
SELECT ROUND(3463.4896, -2); -- 3500
Negative value for decimal place ( D) will affect left of decimal places.
SELECT name, percentage, ROUND(percentage, 0) AS rnd
FROM student4;
Inside round function we can change the number of decimal places required to 1,2,3 etc .. here is an example.
SELECT name, percentage, ROUND(percentage, 2) AS rnd
FROM student4;
Output is here
| name | percentage | rnd | |
|---|---|---|---|
| Max Ruin | 79.2982 | 79.30 | |
| Arnold | 59.6491 | 59.65 | |
| Krish Star | 63.1579 | 63.16 | |
| John Mike | 80.7018 | 80.70 | |
| Alex John | 78.9474 | 78.95 | |
| My John Rob | 72.9825 | 72.98 | |
| Asruid | 89.4737 | 89.47 | |
| Tes Qry | 72.9825 | 72.98 | |
| Big John | 52.6316 | 52.63 |
ROUND() changes the numeric value; FORMAT() returns a display string, and TRUNCATE() removes digits without rounding.
What does ROUND(1234, -2) do?
It rounds to the nearest hundred, giving 1200.
Related: CEIL()
More related tutorials: All math functions, EXP(), STDDEV(), AVG()
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
| barbie | 22-11-2014 |
| what will be the value if negative round is asked? | |