SQL Round Function

前端 未结 7 1345
有刺的猬
有刺的猬 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:39

    It is expected to be 50.

    round(45.923, 0) => 46

    expl: the last non-decimal digit is rounded (5), the desicion is based on the next digit (9) 9 is in the high half, ergo 5 is rounded up to 6

    round(45.923, 1) => 45.9

    expl: the first decimal digit is rounded (9), the desicion is based on the next digit (2) 2 is in the low half, ergo 9 stays 9

    your case: round(45.923, 1-) => 45.92

    expl: the secon-last non-decimal digit is rounded (4), the desicion is based on the next digit (5) 5 is in the top half, ergo 4 is rounded up to 5, the rest of the digist are filled with 0s

提交回复
热议问题