英文:
in round() function, second thing after number to be rounded is negative what will be output
问题
SELECT ROUND(455.23456,-3)
FROM dual;
SELECT ROUND(455.23456,-3)
FROM dual;
This is what I tried, and I don't know what to expect.
英文:
SELECT ROUND(455.23456,-3)
FROM dual;
SELECT ROUND(455.23456,-3)
FROM dual;
this is what i tried, and i don't know what to expect
答案1
得分: 2
ROUND(value, precision)
会四舍五入到最接近的 10<sup>-precision</sup>。
所以:
SELECT ROUND(455.23456,-3) FROM DUAL;
会四舍五入到最接近的 10<sup>-(-3)</sup> = 10<sup>+3</sup> = 1000,并输出:
ROUND(455.23456,-3) |
---|
0 |
因为 455.23456 更接近于 0 而不是 1000。
以及:
SELECT ROUND(455.23456,-2), ROUND(455.23456,-1) FROM DUAL;
输出:
ROUND(455.23456,-2) | ROUND(455.23456,-1) |
---|---|
500 | 460 |
(分别四舍五入到最接近的 100 和 10)。
英文:
ROUND(value, precision)
will round to the nearest 10<sup>-precision</sup>.
So:
SELECT ROUND(455.23456,-3) FROM DUAL;
Will round to the nearest 10<sup>-(-3)</sup> = 10<sup>+3</sup> = 1000 and will output:
ROUND(455.23456,-3) |
---|
0 |
Since 455.23456 is closer to 0 than 1000.
And:
SELECT ROUND(455.23456,-2), ROUND(455.23456,-1) FROM DUAL;
Outputs:
ROUND(455.23456,-2) | ROUND(455.23456,-1) |
---|---|
500 | 460 |
(Rounding to the nearest 100 and 10 respectively.)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论