Number Compacter - Make big numbers short

This is a rather small module that is useful for things like simulators where the value is so big that it can’t be shown fully. This module can deal with numbers from thousand to a googol and put it in a short form of 1 - 3 letters. Some of these numbers are absurd and so big it’s almost impossible to recognise.

Tell me if any numbers are wrong.

Module:

local compacts = {
	[3] = "K"; -- the numbers are the amount of 0's
	[6] = "M";
	[9] = "B";
	[12] = "T";
	[15] = "Q";
	[18] = "QT";
	[21] = "ST";
	[24] = "SP";
	[27] = "OT";
	[30] = "N";
	[33] = "D";
	[36] = "UD";
	[39] = "DD";
	[42] = "TD";
	[45] = "QTD";
	[48] = "QND";
	[51] = "SD";
	[54] = "SPD";
	[57] = "OD";
	[60] = "ND";
	[63] = "VT";
	[66] = "UVT";
	[69] = "DVT"; -- nice
	[72] = "TVT";
	[75] = "QVT";
	[78] = "QNVT";
	[81] = "SVT";
	[84] = "SPVT";
	[87] = "OVT";
	[90] = "NVT";
	[93] = "TT";
	[96] = "UTT";
	[99] = "DTT";
	[100] = "G";
}

function round(a,b)
	return math.floor(a/b)*b
end
function roundD(val, decimal)
	if (decimal) then
		return math.floor( (val * 10^decimal)) / (10^decimal)
	else
		return math.floor(val+0.5)
	end
end
return function(n)return roundD(n/1000,1), compacts[math.clamp(round(math.log10(n),3),0,100)]end

Returns:

local value, str = compact(1500)

print(value) -- prints 1.5
print(str) -- prints K

print(value..str) -- prints 1.5K

--etc etc
10 Likes

This should be “make big numbers short”

1 Like

i never will understand why people use alot of BIG numbers, later on when they wish
to adjust something, it will be very hard if they get lost in the process while finding a
way to balance the game or some mechanic related to it [Stats or something]

Work with small numbers, that’s all i have to say
[ - ]Complex
[ - ] Hard if you stay too much time without messing with those numbers around for a while ( stopped using roblox studio for a long time and then returned and probaly forgot about how the logic of the game worked ) (kinda rare to happen but anyway)
[ + ]Efficient
[ + ] Readable and you can understand fast what’s going on
if you start with small numbers, you will see that :: later, it will be kinda big after alot of
“Upgrades” or as the player progress

Level 1 = 5 Str

level 100 = 1000 Str

now imagine complex numbers

level 1 = 5000 str
level 100 50000000000000000000000000000000 whatever i dind’t calculated nothing-

your eyes will bleed

1 Like

just use math.round instead, it was made for that

math.round(val)
2 Likes

Cool contribution, nice job! Check out the suggestions as well.

I suggest you check the API docs.

My sincere apologies!

Last time I checked the math API docs there was no round function, which was last year.

My bad!

1 Like

This is mostly done to keep player attention. If our brain sees small numbers going up slowly, we will get bored pretty fast. On the other hand, if large numbers go up really fast, It will stimulate the brain more.

1 Like

well…apparently large numbers give people a adrenaline rush so addicting games like to use big numbers.

I can’t believe numbers can be addicting. yo spitting facts

umm, I dont see any link to the module…

What on earth happened here.

@kinglol123468 There is no link, the module is just source code since there would not need to be a link if its just little amounts of code.

@D0RYU I am aware of math.round, but I didn’t use it for this because it doesn’t do a difference, plus im already used to using math.floor for this.

This module was literally a vent, just released because I know one person would actually use this and it probably one be helpful to that one person