local function OddOrEven(Number)
if typeof(Number) ~= "number" then
warn("Must be a number!")
else
local DivededResult = Number / 2
if tostring(DivededResult):find(".") then
return "Odd"
else
return "Even"
end
end
end
local hm = OddOrEven(4)
print(hm)
local function OddOrEven(Number)
if typeof(Number) ~= "number" then
warn("Must be a number!")
else
local DivededResult = Number % 2
if not DivededResult == 0 then
return "Odd"
else
return "Even"
end
end
end
local hm = OddOrEven(4)
print(hm)
I don’t think that is the problem. That is only talking about the precision of decimal numbers not integers. Plus 4/2, 4 and 2 are powers of 2 and will not have a precision error. @HenryThe_Legendary The real reason it happens is because of the operator /. If you divide an integer, it will return a double.
Edit: Actually, I’m not sure about the real reason it says odd, but maybe it is because of string formatting? Apparently using “.” (dot) to ‘find’ just returns 1, which is not equal to nil.
I believe that the dot is a special character, meaning any character, so it matches the first character number , numberstring.find ( string s, string pattern, number init = 1, bool plain = false )
maybe try this:
print(string.find("abc123",".", nil, true))
to turn plain search on, and treat the string as a raw one without regex and special stuff
Try this maybe, as your code will always return Odd if the string have at least one character
local function OddOrEven(Number)
if typeof(Number) ~= "number" then
warn("Must be a number!")
else
local DivededResult = Number / 2
if tostring(DivededResult):find(".", nil, true) then
return "Odd"
else
return "Even"
end
end
end