lua中math.floor值偏差的问题

来源:互联网 发布:怎样装天正软件 编辑:程序博客网 时间:2024/06/06 00:45

math.floor((1.16-1.0)*100) = 15

math.floor(0.16*100) = 16

考虑到可能是lua中数字都是double类型的原因 所以实验了下以下

math.floor(1.9999999999999999) = 2

math.floor(0.9999999999999999) = 1

又疑惑了 为什么判断出这种结果

目前用了规避方式就是做这种运算的时候先保留6位有效数字 然后再做math.floor