您现在的位置: 万盛学电脑网 >> 程序编程 >> 网络编程 >> 编程语言综合 >> 正文

Lua math.fmod使用时的小数问题

作者:佚名    责任编辑:admin    更新时间:2022-06-22

   这篇文章主要介绍了Lua math.fmod使用时的小数问题,math.fmod用于取模运算,使用小数时可能会遇到不可预料的结果,所以应该避免使用小数,需要的朋友可以参考下

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 lua math.fmod使用注意小数: --Returns the remainder of the division of x by y. function math.fmod (x, y) end //取模运算   这里需要注意小数的问题,看下面两个例子: 1、 local x = math.fmod(15, 4) print(x)   结果:4   2、 local x = math.fmod(15.3, 4) print(x)   结果:3.3   3、 local x = math.fmod(15, 4.1) print(x)   结果:2.7