Adding commas to number? e.g 1000 to 1,000?

I still dont understand what you are saying man

You know what? I sort of take back my suggestion to use @Tiffblocks’s solution.

Is it the best solution? Yes, unambiguously, you should use it for serious projects that you want to localize.

ROBLOX provides really cool and powerful tools to translate your game. Here’s an introduction to how localization works, and here is an introduction to how to bridge the gap between your game’s localization table, and your script showing a number.

However, that’s a lot of API for not a lot of benefit IMO. It’s not like the rest of your game is localized, anyways. Just (and some people would probably yell at me for suggesting this) use a stupid american-english-only function for this specific case.

Who cares? Are you planning on a lot of brits playing your game and worried about them being confused that there’s commas instead of periods? You’re not building a AAA game here.


I stole this from the link I posted earlier. Just use it and move on with your game.

function format_int(number)

  local i, j, minus, int, fraction = tostring(number):find('([-]?)(%d+)([.]?%d*)')

  -- reverse the int-string and append a comma to all blocks of 3 digits
  int = int:reverse():gsub("(%d%d%d)", "%1,")

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

print(format_int(1000000)) -- prints 1,000,000
print(format_int(1000000.5555)) -- prints 1,000,000.5555
9 Likes

What isn’t efficient about any of these answers???

7 Likes