Possible Duplicate:
Lua - Format integer
我如何格式化一个整数,比如1000000,它返回1.000.000?
这可以通过使用printf
来管理吗?有人知道怎么做吗参数是什么样的?
我目前正在使用Corona SDK
/Lua
并且有一个类似于printf
的格式函数。
最佳答案
你需要一个自定义函数。类似于:
function comma_value(amount)
local formatted, k = amount, 0
while true do
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
if (not k) or k==0 then
break
end
end
return formatted
end
更多number formatting functions。
关于c - lua中的printf格式,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12353826/