`
caiwb1990
  • 浏览: 309043 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Lua金钱显示工具

    博客分类:
  • lua
阅读更多
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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics