% 运算符的 Lua 替换 [英] Lua replacement for the % operator
本文介绍了% 运算符的 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?
谢谢.
推荐答案
并不理想,但根据 Lua 5.2 参考手册:
a % b == a - math.floor(a/b)*b
a % b == a - math.floor(a/b)*b
这篇关于% 运算符的 Lua 替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文