in round() function, second thing after number to be rounded is negative what will be output

huangapple go评论48阅读模式
英文:

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

fiddle

huangapple
  • 本文由 发表于 2023年4月19日 18:59:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76053696.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定