- 欢迎光临Satisfactory国区BWIKI。请登录您的B站账号,方可使用页面编辑与评论功能。

全站通知:

模块:FormatNumber

来自幸福工厂WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模块的文档可以在模块:FormatNumber/doc创建

local p = {}

p.formatNumber = function(number)
  -- if it was called via {{#invoke}} then number is a frame object and args[1] is the first argument
  if type(number) == 'table' then
    number = number.args[1]
  end
  
  local i, j, minus, int, fraction = tostring(number):find('([-]?)(%d+)([.]?%d*)')
  
  if int == nil then
    return number
  end
  
  -- reverse the int-string and append a separator to all blocks of 3 digits
  int = int:reverse():gsub("(%d%d%d)", "%1 ")

  -- reverse the int-string back remove an optional separator and put the 
  -- optional minus and fractional part back
  return minus .. int:reverse():gsub("^ ", "") .. fraction
end

return p