How would i remove the zeros between the decimal and 2?

I want to create a function that can remove zeroes between a decimal and a number, for example:
0.002496911445632577
I want to be able to turn this number above

0.2496911445632577
into this

I want this function to be able to work on any number that looks like the first number at the top of this post. I don’t know where to begin and I already tried but failed does anyone know how I would go about this?

Hi there, see below!

local function InputNumber(val)
	if val < .1 then
		val *= 10
		return InputNumber(val)
	else
		return val
	end
end

local test = InputNumber(.00005608))
print(test)

We create a function which starts by checking the value inputted if it’s lower than .1, if it is, then we multipley it by 10 to reduce one of the 0’s and then we send it back through the loop, if the loop finds that the value eventually reaches over then .1 then it returns the value. Since the code loops through itself with the return values, it will eventually return the value desired. Should work on any value lower than that too, without limit

thank you for the solution and explanation! it all worked perfectly! :smile:

1 Like