Don't know why my script is printing 17 instead of 2

I’m trying to count how many digits are past the decimal point of a number in my script.

local Size = UDim2.new(0.05,0,0.1,0)

local AODX = string.len(string.split(tostring(Size.X.Scale), ".")[2])
local AODY = string.len(string.split(tostring(Size.Y.Scale), ".")[2])

print(AODX.. "    ".. AODY)
1 Like

It might be due to floating point errors with decimals where numbers be like 0.4999999999 which is equal to 0.5.

It would be best to round it up to the hundredths place or avoid decimals.

2 Likes

Turned numbers into strings to fix it

local SizeX = "0.05"
local SizeY = "0.1"

local Size = UDim2.new(tonumber(SizeX),0,tonumber(SizeY),0)

local AODX = string.len(string.split(SizeX, ".")[2])
local AODY = string.len(string.split(SizeY, ".")[2])

print(AODX.. "   ".. AODY)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.