Satisfactory Wiki
Advertisement
Satisfactory Wiki
Template-info.png Documentation

{{#invoke:FormatNumber|formatNumber|1234567}} turns 1234567 into 1 234 567


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
Advertisement