Lua金钱显示工具
function StringTool:dealMoney(money,lenth)
local moneyStr
local dealLength = 3
if lenth then
dealLength = lenth
end
if type(money) == "string" then
money = tonumber(money)
end
local function trimMoney (value)
local restr = value
if string.len(value) > (dealLength + 1) then
restr = string.sub(value, 1, (dealLength + 1))
local index = string.find(restr,"%.")
if index == (dealLength + 1) then
restr = string.sub(restr,1,dealLength)
end
end
return restr
end
if type(money) == "number" then
if money >= 1000000000 then
moneyStr = trimMoney(money / 1000000000) .."B"
elseif money >= 1000000 then
moneyStr = trimMoney(money / 1000000) .."M"
elseif money >= 1000 then
moneyStr = trimMoney(money / 1000) .."K"
else
moneyStr = money
end
end
return moneyStr
end