SQL Round Function

前端 未结 7 1332
有刺的猬
有刺的猬 2021-01-13 10:00

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 suggestin

7条回答
  •  南方客
    南方客 (楼主)
    2021-01-13 10:35

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

提交回复
热议问题