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 |
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? | |