String Formatting

How do I make it NOT use a decimal, when it’s just plain out 5,000, or something like that, so it’d just be “5k” instead of “5.00K”

local SuffixList = {"", "K", "M", "B", "T", "Q", "s", "S", "o", "n", "d"}

local function Format(value, idp)
	local exp = math.floor(math.log(math.max(1, math.abs(value)), 1000))
	local suffix = SuffixList[1 + exp] or ("e+" .. exp)
	local norm = math.floor(value * ((10 ^ idp) / (1000 ^ exp))) / (10 ^ idp)
	return ("%." .. idp .. "f%s"):format(norm, suffix)
end

1 Like
local suffixes = {'','K','M','B','T','qd','qn','sx','Sp','O','N','de'}
local function format(val)
	for i=1, #suffixes do
		if tonumber(val) < 10^(i*3) then
			return math.floor(val/((10^((i-1)*3))/100))/(100)..suffixes[i]
		end
	end
end

In my opinion this is much better

1 Like

Can you give me a detailed explanation? That is math, I failed my Math 2 class.

Please :pleading_face:

2 Likes

I am not good at explaining at all, and I wont much to bore you with this stuff (I’m in 10 grade still learning math) basically for all of the suffixes, if the (value) is less than 10 to the power of (the suffix # in the list) * 3 then round (value) divided by blablabla divided by 100 and that rounded number divided by 100 gets you the result? :smiley:
its really late for me, sorry :sweat_smile: