Yeah, that didn’t really work. What I’ve decided to do is, get the number, then use math.floor and compare values. If values are the same, it’s not a decimal. If the values are different, then it is a decimal.
local spp = math.floor(sp)
tostring(spp)
tostring(sp)
print(spp)
print(sp)
if spp == sp then
print("its not a dec")
else
print("its a dec")
end
local Value = game.Players.Conejin_Alt.leaderstats.Coins
local ValueWithNoDecimals = math.floor(Value.Value)
if ValueWithNoDecimals == Value then
--Code here
end
If % doesn’t work then you can try it, this should find the “.”:
local number = 32.321321321
local function IsADecimal(number)
print("to check:",number)
if tostring(number):split(".")[1] == tostring(number) then
return false
else
return true
end
end
if IsADecimal(number) then
print("a decimal")
else
print("a number")
end
This should work just fine as well I guess, haven’t rly tested it.
local pattern = "%p%d+"
local num = 23
local str = string.match(num, pattern)
if str == nil then
print("not a decimal")
else
print("is a decimal", str)
end
if type(var) == "number" then
print("number")
if var ~= math.floor(var) then
print("decimal number")
else
warn("non-decimal number")
end
else
warn(type(var))
end
I know that I am pretty late but here is my solution that isn’t too complicated to understand.
local NumberWithDecimal = 1.1 --You can play around with this.
if math.floor(NumberWithDecimal) == NumberWithDecimal then
print("Doesn't contain a decimal!")
else
print("Contains decimal!")
end
What this basically does is check whether the math.floor of a number is the same as the original number.
function isDecimal(number)
return math.floor(number) ~= number
end
print(isDecimal(67)) --false
print(isDecimal(6.7)) --true
if isDecimal(78.6) then
print("Hey! 78.6 is a decimal!")
end