Created
April 26, 2020 21:35
-
-
Save Blockzez/36680698a15aef51cd548d6b90038ff0 to your computer and use it in GitHub Desktop.
Quick locale-unaware positive integer formatting for Roblox Lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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