用Lua代替%运算符 [英] Lua replacement for the % operator

查看:75
本文介绍了用Lua代替%运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查一个数字是否可以被另一个数字整除:

I want to check, if a number is divisible by another number:

for i = 1, 100 do
    if i % 2 == 0 then
        print( i .. " is divisible.")
    end
end

这应该可以正常工作,但是如果脚本中有%,则在我的服务器中使用Lua脚本不会运行...我不知道是什么原因,因此是否有任何替换"为了那个原因?这样我可以检查数字的可分性吗?

This should work without any problems, but with the Lua in my server the script doesn't run if there is a % in the script... I dont know whats the reason, so is there any "replacement" for that? So I could check the number divsibility?

谢谢.

推荐答案

这并不理想,但根据

a%b == a-math.floor(a/b)* b

a % b == a - math.floor(a/b)*b

这篇关于用Lua代替%运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆