Number Shortener Not Working

Okay, so I have been trying to make a number shortener, and when i test the number shortener with something past the millions like 1.1e15, it returns 110000000M+. What would be the problem here?
code:

local numlength = 0
local stringnumber = ""
local shortenednum = 0
local module = {}
local shorten = 3
local range1 = 3
local range2 = 6

function module:ConvertNumber(number)
	if typeof(number) == "number" then
		print("Is confirmed to be a number")
	numlength = string.len(tostring(number))
	local function yes(word)	
			if number >= 10^range1 and number <= 10^range2 then
				--print(range1)
				print(number)
			stringnumber = string.format("%.2f"..word, number / (10^shorten))
			--print(stringnumber)
				print(stringnumber)
		end
	shorten = shorten + 3
				range1 = range1 + 3
				range2 = range2 + 3
			

		end
			--number = tonumber(string.sub(tostring(number),0,3))
				yes("M+")
		yes("B+")
		yes("T+")
		yes("QD+")
		yes("QN+")
		yes("SX+")
		yes("SP+")
		yes("OCT+")
		yes("NON+")
		yes("DEC+")
		yes("UND+")
		yes("DUOD+")
		yes("TRED+")
		yes("QUATTUROD+")
		yes("QUIND+")
		yes("SXD+")
		yes("SPD+")
		yes("OCD+")
		yes("NOND+")
		yes("VIGN+")
		yes("UNVIGN+")
		yes("DUOVIGN+")
		yes("TREVIGN+")
		yes("QUATTUROVIGN+")
		yes("QUINVIGN+")
		yes("SXVIGN+")
		yes("SPVIGN+")
		yes("OCTVIGN+")
		yes("NONVIGN+")
		yes("TRETRIG+")
		yes("UNTRETRIG+")
		yes("DUOTRETRIG+")
		yes("TRETRETRIG+")
		yes("QUATTUROTRETRIG+")
		yes("QUINTRETRIG+")
		yes("SXTRETRIG+")
		yes("SPTRETRIG+")
		yes("OCTTRETRIG+")
		yes("NONTRETRIG+")
		yes("QUADRIG+")
		yes("UNQUADRIG+")
		yes("DUOQUADRIG+")
		yes("TREQUADRIG+")
		yes("QUATTUROQUADRIG+")
		yes("QUINQUADRIG+")
		yes("SXQUADRIG+")
		yes("SPQUADRIG+")
		yes("OCTQUADRIG+")
		yes("NONQUADRIG+")
		yes("QUINQUAG+")
		--number = stringnumber
			return stringnumber
		
	else
		warn("attempt to get number from another thing that is neither a number nor does it have a number. please make it a number before using this or it will not work")
	end
	end
return module

any help would be appreciated!

1 Like

A way I would suggest doing this is by converting your raw number input into a string, and finding the length of the string. The length of the string would be able to determine which order of magnitude the number is (ie is it millions, billions etc.) as we know that a 7-9 length long number will be in the millions.

Hope this shines a light on a more simple solution to what you’re trying to achieve, -Tom :slight_smile:

1 Like

i already tried that, and when i do things like 1e15, it returns only 5 instead of 16, making it useless when you get past the billions

1 Like

Ohhh I see, well do you know for sure that all numbers are going to be in standard form denoted by “e”? If so, the string.find function might be worth looking at to identify the mantissa and the exponent.

1 Like

ok, so i fixed it, and the error was caused by me not putting my variables in the right place. the variables should have been in the function, not out.

1 Like