Abhi’s Number Abbreviation System
The best, most compact, and most efficient abbreviation system that you’ll ever find!
Hot fix (must read)
New hot fix released on Aug 1, 2020, 5:20 pm. If you are still using an old version, please switch to the new one! V 2.2
→ V 2.3
About
In games, we generally need to cram more and more information in lesser, and lesser space. In terms of numbers, we often have to crunch numbers like 2000
to 2K
. This can be done using loops and other recursive systems. But what are you didn’t? Meet Abhi’s Number Abbreviation System! This system uses clever techniques that come to my mind at 12 in the night, because that is how I work.
How it works
It’s simple
- Break a number into 3s
-
123456
→123
+456
-
- Take the foremost part
-
123
+456
→123
-
- Concate it with the appropriate multiplier
-
123
→123K
-
- Bam, you are done!
Source Code (must read)
local suffixes = {"", "K", "M", "B", "T", "QA", "QI", "SX", "SP", "OC", "NO", "DC", "UD", "DD", "TD", "QAD", "QID", "SXD", "SPD", "OCD", "NOD", "VG", "UVG"}
function abbreviate(n)
-- Abhi's Number Abbreviation System V 2.4
local s = tostring(math.floor(n))
return string.sub(s, 1, ((#s - 1) % 3) + 1) .. (suffixes)[math.floor((#s - 1) / 3) + 1]
end
Speed and reliability (must read)
The script usually takes about 0.4 to 0.05 milliseconds to run. The script will be able to handle numbers up to math.huge
, but limits itself to (10 ^ (23 * 3)) - 1
. That is a 1
, followed by 69
zeros (it’s funny, now laugh). The script is reliable even with decimals as it just rounds down.
Distribution (must read)
Use it in your games, no need to credit me in your source code. But if you are sharing this through media means, please do credit.
Use
This script is recomended to be used in leaderboards, and other areas in GUIs.
Notes
This doesn’t round up, meaning 123999
will become 123K
and will not be rounded up to 124K
. Also, the output is a string, if you haven’t realized that yet .