MySQL ROUND() Function: Round numbers to a chosen decimal place

ROUND(number, decimals) rounds a numeric value. A negative decimals argument rounds to places left of the decimal point.

ROUND(): Quick SQL Example

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
On this page — Show page sectionsHide page sections

More SQL Examples and Explanations

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

Rounding off data up to 2 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.

We will use our student table and get the rounded data by using round query.

Example

Percentage is a column name in our student table.
Here we store the percentage value of each student mark. One of our student Max has got 79.2982 percentage. This number we can round off and display without any decimal value by using command like this.
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
namepercentagernd
Max Ruin79.298279.30
Arnold59.649159.65
Krish Star63.157963.16
John Mike80.701880.70
Alex John78.947478.95
My John Rob72.982572.98
Asruid89.473789.47
Tes Qry72.982572.98
Big John52.631652.63
Try with different values The sql dump of student4 table is here .
SQL dump of Student4 table here

How to Interpret the Result

ROUND() changes the numeric value; FORMAT() returns a display string, and TRUNCATE() removes digits without rounding.

Common Question

What does ROUND(1234, -2) do?
It rounds to the nearest hundred, giving 1200.

Further Reading

All Math Functions TRUNCATE()

Related: CEIL()

More related tutorials: All math functions, EXP(), STDDEV(), AVG()

↑ Back to top




Subscribe to our YouTube Channel here



plus2net.com
barbie

22-11-2014

what will be the value if negative round is asked?




SQL Video Tutorials










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer