Number Beautify Module!

Hello!! Thanks for looking at my post! This is a module I made which I really like, and will use on my own games!
This module allows you to have more “beautiful” numbers! Like, having 23K instead of 23000.
Or having 23,000 instead of 23000.

This does all that for you.


Currently it has two functions:

beautifyModule:AddCommas(number)

This one adds commas to the numbers. It has a limit of about 1 trillion / quadrillion (not sure rn)
But it should do everything fine, and if it doesn’t support that value it would simply give you the raw number, so no worries about it not showing data.

Examples:

image
image
image

Code Example:

local beautifyModule = require(game.ReplicatedStorage.NumberBeautify)
local number = 10000000     -- 10 Million.
local convertedNumber = beautifyModule:AddCommas(number)
print(convertedNumber)

Result:

image


beautifyModule:Simplify(number)

This function adds a (“K”, “M” or “T”) in the end and makes the number easier to read overall.

Examples:
image
image
image

Code Example:

local beautifyModule = require(game.ReplicatedStorage.NumberBeautify)
local number = 250000     -- 250 thousand.
local convertedNumber = beautifyModule:Simplify(number)
print(convertedNumber)

Result:
image


https://www.roblox.com/library/6149957723/Number-Beautify-Module

Any new functions that we together can add, since this is open-source can be added if theres a reply or message about it to me / to this topic.

This module will still be updated, for glitches, and features. I will make sure that will still work with older code! No worries! :wink:

If you need help with the code to make this work, you can message me. I recommend not replying for questions like that! I’ll be sure to answer you since I’m pretty active here!

Happy Christmas! (It’s 28th December nevermind…) but still!

22 Likes

This is amazing! I will defiantly use this in my games, Thank you!

3 Likes

i’m surprised there’s so many likes at once! :smiley: never had that happening … thanks :wink:

3 Likes

Is it alright if I use a snippet from the module in my game so I don’t need to use ModuleScripts? Great resource by the way!

1 Like

Sure? do you mean like getting the code and intregating it into yours? Yeah, as long as you don’t share as if it was yours, but sure! :wink:

2 Likes

If AddCommas is intended to clean up a number with commas, is there a reason why there’s a limit to the number until it stops adding commas? Does your code not arbitrarily handle this and did you instead hard code it to add commas with greater/less than (equal to) operators?

What about higher values? Some developers work with far more than a trillion, especially those in the simulator business.

3 Likes

Looking at the code, it’s not that hard to add new values.

2 Likes

This is amazing work! Nice job! One thing in particular that you may find useful and can use to make your module even better is this function (not mine), this formats any large numbers, no matter the size:

function convertLargeNumbersIntoStringNotation(number)
	if number <= 1000 then
		return number
	elseif tostring(number):match("inf") then
		return "inf"
	elseif number >= 1e45 then
		return string.format("%.1fQu", number/1e45)
	elseif number >= 1e42 then
		return string.format("%.1fTr", number/1e42)
	elseif number >= 1e39 then
		return string.format("%.1fD", number/1e39)
	elseif number >= 1e36 then
		return string.format("%.1fU", number/1e36)
	elseif number >= 1e33 then
		return string.format("%.1fDe", number/1e33)
	elseif number >= 1e30 then
		return string.format("%.1fN", number/1e30)
	elseif number >= 1e27 then
		return string.format("%.1fO", number/1e27)
	elseif number >= 1e24 then
		return string.format("%.1fSe", number/1e24)
	elseif number >= 1e21 then
		return string.format("%.1fS", number/1e21)
	elseif number >= 1e18 then
		return string.format("%.1fQt", number/1e18)
	elseif number >= 1e15 then
		return string.format("%.1fQ", number/1e15)
	elseif number >= 1e12 then
		return string.format("%.1fT", number/1e12)
	elseif number >= 1e9 then
		return string.format("%.1fB", number/1e9)
	elseif number >= 1e6 then
		return string.format("%.1fM", number/1e6)
	elseif number >= 1e3 then
		return string.format("%.1fK", number/1e3)
	end
end
3 Likes

Not my problem or my question.

For a number beautifier, I would expect that for a function like adding commas to a number that the function could accept arbitrary numbers and determine where commas need to be added according to that number. There shouldn’t be a limit to the number before it stops adding commas unless Lua literally cannot handle the number provided. It leads me to believe that there’s hardcoding of an if chain which is an anti-practice and not good for systems like this.

My second question is of the same nature. You may need to manually write out the suffixes somewhere at least, but I’d think you’d be able to do so in an array and then use a mathematical function to determine which suffix to use. If there’s only three supported suffixes on a beautifier, this again leads me to believe that it’s a hardcoded if-chain rather than arbitrarily handling numbers.

Sure, I can add things in myself, but I find that it’d be much easier if a beautifier like this arbitrarily handled my numbers so I don’t have to do it and I don’t have to constantly maintain a bunch of if-else statements whenever I need the module to handle bigger values. I can fork it for myself and modify it but it’s better if the community has access to all the changes made for the module.

EDIT: Went on a search and found stuff I’m looking for. For reference, Formatting Numbers on the lua-users wiki. This is what I mean by arbitrarily handling numbers. Might be good to look into this kind of thing when it comes to cleaning up numbers.

2 Likes

I was thinking if that chill. It feels like people find things to be annoyed about gosh. As I said:

If I want to add a better way to do that, sure. But right now I don’t find it that bad. I can’t find a use case where you would use a number higher than a quadrillion on a GUI. So as I said I might add better detection. I’m just learning a bit how to do that. Plus it works no matter what, even if the number is too high, the raw number would be there, wouldn’t cause problems.

1 Like

I don’t really use any lua wiki. I don’t classify myself as a Lua learner, more like a Roblox Lua Learner.

Kinda different to me. Since roblox works in very specific ways.

1 Like

Gosh this hurts my eyes. I’m confused but sure. Do you know the limit to that?

No limits at all :slightly_smiling_face:
plugging in math.huge will return “inf”

1 Like

I’m not mad or annoyed. It’s a genuine question asking why there’s limitations on the extent of values that your module can handle. I did end up finding some other resources that can handle arbitrary numbers though and I do recommend checking those out if you’re looking for improvements for your module.

Mentioned in my first post:

As for the Lua Wiki post, that’s just a community site for sharing code and knowledge like the DevForum is. I linked that there because I went to go search for an example of what I was talking about and found it; and also suggested it might be a good place to check up with.

1 Like

Sure. I have these limitations because of the methods I used, using string.sub (i hated it) and getting the places where there needs to be a comma but anyways

1 Like

I think the word you’re looking for is abbreviate not beautify lol. I still like the module though.

1 Like

Would you be adding a decimal feature? Like the number is 200320. Instead of turning it into 200k, it becomes 200.3k? Or 200.32k?

This is what I mean: here

I feel that your module would be better and used more, so you might consider to use the feature about adding decimal places in the simplify feature

2 Likes

Here’s the thing, I was thinking of not including that. But it’s “harder” to make it only 200k. My method is

local baseNumber = 1250 / 1000
return baseNumber.."K"

If i wanted for it to only be 1000 I would do math.floor or math.round on baseNumber

I do wanna make it better. I feel like having 200.32 for example it’s a bit too much, I would remove the 2 from there. Gonna look into it.

2 Likes

I have to ask why is it in : and not . when you’re not using self that’s passed via :?
Is there anyway to change the precision for both of these methods?


Why not like in Unicode ICU? What about NaN? Signed (negative) number? This is all very basic standard values I expect to work.


A decimal comma? AddComma is misleading to people from many European countries like me usually use , as a decimal separator.

Eh, do you have another name for it?