I would like to be abble to round up or down 10.823. Expected result:
rounding down = 10.82
rounding up = 10.83
Knowing that round(10.823, 2)
only rounds down. How to round it up?
SQL Server ROUND() Function The ROUND() function rounds a number to a specified number of decimal places.
SQL ROUND Function You might have known CEILING and FLOOR, but ROUND is by far the most common. Rounding just means to round up from 5 or down from anything less. ROUND is unique because you can tell SQL which position you would like rounded.
The SQL FLOOR() function rounded up any positive or negative decimal value down to the next least integer value. SQL DISTINCT along with the SQL FLOOR() function is used to retrieve only unique value after rounded down to the next least integer value depending on the column specified.
You are correct, round
is the wrong tool for this job. Instead, you should use floor
and ceiling
. Unfortunately, they do not have a precision parameter like round
, so you'd have to simulate it using division and multiplication:
SELECT FLOOR(value * 100) / 100 AS rounded_down,
CEILING(value * 100) / 100 AS rounded_up
FROM mytable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With