Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Blockzez
Created April 26, 2020 21:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Blockzez/36680698a15aef51cd548d6b90038ff0 to your computer and use it in GitHub Desktop.
Save Blockzez/36680698a15aef51cd548d6b90038ff0 to your computer and use it in GitHub Desktop.
Quick locale-unaware positive integer formatting for Roblox Lua
local suffix={'K','M','G','T','P','E','Z','Y'};function FormatInteger(n)return tostring(math.floor(n)):reverse():gsub('%d%d%d','%1 '):gsub(' $',''):reverse()end;function FormatCompactInteger(n)return((((n<1000)and(n)or math.floor(n/(1000^math.floor(math.log10(n)/3))*((math.log10(n)%3<1)and 10 or 1))/((math.log10(n)%3<1)and 10 or 1))..(suffix[math.floor(math.log10(n)/3)]or'')):gsub('[.]',','))end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment