为什么四舍五入取决于数字?

时间:2018-08-20 12:47:25

标签: r

我不理解,帮助也没有说出取决于数字的回合:

a <- 22.899999999999999
# [1] 22.899999999999999
options(digits = 20)
round(a, 1)
# [1] 22.899999999999999
options(digits = 7)
round(a, 1)
# [1] 22.9
options(digits = 20)
round(a, 1)
# [1] 22.899999999999999

1 个答案:

答案 0 :(得分:2)

不是,round只是返回您的原始号码。

identical(a,round(a,1))
[1] TRUE

digits中更改options会影响显示这些数字的方式