How to find the number of decimal places

I want to find the number of decimal places in a number, including numbers that are padded.

5.194 --> 3
12.0001 --> 4
1.0 --> 1
4.50 --> 2
5 --> 0

The main problem I am encountering is that when I turn the decimal part of the number into a string so I can check its length, 0001 would turn into 1.

You can use math.modf:
Returns two numbers, the integral part of x and the fractional part of x.


x = 4.50
math.modf(x) → 4, 0.50

I recommend the option above, but if you want a different way. Convert the number to a string and split it with a divider of “.”

function GetDecimals(Num)
	return #(tostring(Num):split(".")[2])
end

print(GetDecimals(12.52812)) -->> 5