Simulator Number Abbreviation System With Custom Decimals

as in change the Abbreviations, floor and log10 variable to A, f and l10?

Edit: I mean to make it easier to read?

im not saying you must, its your choice

Thanks. I’ll see if I can apply this to my code.

I’ve got to agree with @regexman that the math.floor variable and math.log10 variable make it soooo much more confusing. It might not be to you as you wrote it therefore you know what every part does but to a person trying to implement this into their game it is very confusing and almost impossible to read. I would also recommend adding comments on each line explaining what it does because of all the math it’s doing, just to help out the beginner developers using this.

I don’t understand? what is the confusing part. What math.floor and math.log10 do?
Also it’s a community resource and not a tutorial.

1 Like

Caching library functions in variables is not confusing or impossible to understand. I do this all the time to make my code more readable when necessary. Stop harassing the creator of this resource for a style choice they made. If you don’t like it then change it to your liking.

6 Likes

You want it to be readable, code isn’t just about making something that works, you need to be able to fix it easily.

Take this for example.

do function test() while thing do function2() end end test() end

if something was to go wrong there (let’s say function2, tracking it would be very hard as it’s all on one line), compared to this:

do
  function test()
    while thing do
      function2()
    end
  end
end

The code doesn’t need to be super short to run fast either, it still will take roughly the same time.
I’ve also made a NumberAbbreviator module, this seems a lot more readable than your functions.

local Abbreviator = {
	Suffixes = {"","K","M","B","T","Q","QN","S","SP","O","N","D","UD","DD"},
	Precision = 3
}

local Floor = math.floor
local Log10 = math.log10

function Abbreviator:ShortenNumber(number, precision)
	self.Precision = precision or 3
	local suffixes = self.Suffixes
	
	local index = Floor(Log10(number))
	index = index - (index % 3)

	local suffix = suffixes[(index / 3) + 1]
	
	local nearestMultiple = 10 ^ index
	local precisionMultiple = 10 ^ self.Precision
	
	local result = Floor((number / nearestMultiple) * precisionMultiple) / precisionMultiple .. suffix
	return result	
end

-- ...

return Abbreviator

VS:

function Module.AbbreviateN(N: number, D) -- N = Number. D = Decimals.
	return f(((N < 1 and N) or f(N) / 10 ^ (l10(N) - l10(N) % 3)) * 10 ^ (D or 3)) / 10 ^ (D or 3)..(A[f(l10(N) / 3)] or "")
end

We aren’t doing that, all we’re saying is that the code should be set out neater if it’s a community resource, because at the end of the day we might want to change some of it aswell. I will say @luisgamercooI231fan you might want to tone down how you write some comments, but that’s it.

It’s a free resource, the creator isn’t obligated to do anything for anyone; they just shared it. Instead of telling the creator how they should have made it, make your own resource.

1 Like

We aren’t forcing the creator to change how their code works, all we’re suggesting is that you should probably make the code a bit neater for people to read.

We’re only suggesting changes that could be made, at the end of the day, it’s their decision whether they want to do it

Nice thanks! I’ll be using this for an upcoming game!

Damn, everyone so hot headed nowadays, while you guys keep there fighting over readability and some different things, I’ll just say thanks for the contribution, although it’s a bit confusing to read and see how it works because of the name of the variable itself, what matters for me in the end is that it just works.

I’m sorry to burst here but, I’m just saying that he used unnessecary variables and then he came up with ‘readability’

Neither if it’s a tutorial or resource, it still needs to be readable if people are gonna use it. Just don’t make unnessecary variables, it dosent make it “readable”

I get where you’re coming from and I do agree that they are indeed unnecessary, but I think they you guys are paying too much attention to a point that, yes it was a mistake, but he did make a resource that works and that has a new feature compared to some of the other scripts that do something similar, such as the decimal amount customization.

Just because it works dosent mean it’s good, thus we didn’t pay too much attention to it, we later paid attention to “readability” as that guy brang up


Anyway, this resource is good but it just needs to be more “readable” as you’re focusing in

Also, were not “harrasing”, if we’re trying to make his code better, we should tell him.

Edit: didn’t mean to reply, srry

All good haha, agree with your quote aswell haha

Pretty clearly speed, most other ones are trashy using tables, and very ineficient

Well then I’m assuming your very experienced as a programmer, but think back to when you started scripting. Wouldn’t you be confused if you saw that? I know I would.

Could you tell me the unnecessary variables inside of my script?
Also I’m not going to use math.floor and math.log10 10 times in the same line of code when I can create a variable for both to shorten it and not make one line of code 100 letters longer.