Lua math.fmod使用时的小数问题
更新时间:2015年06月29日 09:27:15 投稿:junjie
这篇文章主要介绍了Lua math.fmod使用时的小数问题,math.fmod用于取模运算,使用小数时可能会遇到不可预料的结果,所以应该避免使用小数,需要的朋友可以参考下
(福利推荐:【腾讯云】服务器最新限时优惠活动,云服务器1核2G仅99元/年、2核4G仅768元/3年,立即抢购>>>:9i0i.cn/qcloud)
(福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun)
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
相关文章
Cocos2d-x中调用Lua及HelloWorld.lua源码分解
这篇文章主要介绍了Cocos2d-x中调用Lua及HelloWorld.lua源码分解,本文最后总结了一些Lua的语法,需要的朋友可以参考下2014-09-09
最新评论