ROUND()
Rounds a numeric value to a specified number of decimal places.
Description
ROUND rounds a numeric value to a given number of decimal places, using
standard rounding rules (0.5 rounds up). It's most often used to clean up
prices, averages, and other calculated values for display.
Syntax
ROUND(number, decimals)Parameters
| Name | Description | Optional |
|---|---|---|
| number | The numeric value or column to round. | No |
| decimals | How many digits to keep after the decimal point. A negative value rounds to the left of the decimal point (for example, to the nearest 10). | Yes, defaults to 0 |
Return Type
ROUND returns a DOUBLE (or the same numeric type as the input), not a
formatted string, so the result can still be used in further calculations.
Examples
Loading database engine...
Loading database engine...
ROUND with a negative decimals argument
ROUND(price, -1) rounds to the nearest 10 instead of the nearest decimal
place. This is a lesser-known trick for bucketing numbers, like rounding
prices to the nearest $10.
Common Mistakes
- Confusing
ROUNDwith truncation.ROUND(4.567, 1)gives4.6, not4.5, because it rounds rather than simply cutting off digits. - Assuming
ROUNDformats the number as text with trailing zeros.ROUND(4.50, 2)may display as4.5depending on the client, since the underlying value is still a number, not a formatted string with a fixed number of digits. - Forgetting the second argument. Omitting
decimalstypically rounds to a whole number, which may not be what you intended when you just wanted to trim a couple of digits.
Related Functions
See also: CAST, SUM, AVG.