<分区>
Possible Duplicate:
Lua - Format integer
我如何格式化一个整数,比如 1000000 以返回 1.000.000 的方式?
这可以通过使用 printf
来管理吗?有人知道怎么做吗?参数是怎样的?
我目前正在使用 Corona SDK
/Lua
并且有一个类似于 printf
的格式功能。
<分区>
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
关于c - lua中的printf格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12353826/