SQL Round Function


round(45.923,-1) gives a result of 50. Why is this? How it is calculated?

(sorry guys i was mistaken with earlier version of this question suggesting value was 46)

Best Solution

The SQL ROUND() function rounds a number to a precision...

For example:

round(45.65, 1) gives result = 45.7

round(45.65, -1) gives result = 50

because the precision in this case is calculated from the decimal point. If positive then it'll consider the right side number and round it upwards if it's >= 5, and if <=4 then round is downwards... and similarly if it's negative then the precision is calculated for the left hand side of decimal point... if it's >= 5

for example round(44.65, -1) gives 40 but round(45.65, -1) gives 50...