Checking Number Types in Luau

Hello, so basically I am wondering how i can check for number types.

In Regular Lua, there is a math function known as math.type() which would allow you to check what type of number a number is, Like if its a Float, or if its an Integer.

Basic Rundown:

Float is a number with Decimals
Integer is a whole number

However in Luau, It is known as a Double rather than a Float, which I don’t understand why, and yet people get confused for angry when I call it a Float instead of a Double

math.type(12)   --> integer
math.type(21.1) --> float (or "double")

There is Obviously a whole lot more to my statement of:

But this is just supposed to be a Basic Rundown, and I want to stay on Topic, so I wont get into that


But Inside Luau, math.type() doesn’t exist like with many other math functions, and It doesn’t appear to be Documented under Compatibility or Type Checking, unless I’m not looking thoroughly enough (which is likely the case), However, there may be reasons for math.type() not being in Luau that I’m probably not aware of.

How would I check for number types within Luau as it doesn’t appear to have this simple function like Lua?

math.type() doesn’t exist in Luau like I said.

I think you’re going to need to manually check using small code lines.

For example, if you needed to check if a number is a floating point you would do something like this:

local Number = 10.25

if Number ~= math.round(Number) then
    print(floatNumber .." is a float number!")
end

I found this solution somewhere on devforum: Is there any way of detecting if a number is a floating point? - #3 by JakeTheHero89

This isn’t perfect, It continues to print Number.." is a float number!" when it clearly isn’t

local Number = 10 -- should be a "integer" so it shouldn't print

if Number ~= math.round(Number) then
    print(Number .." is a float number!") -- Still Prints
end

Ok well, I didn’t read the entire post but this the updated method

That works, Thank you.

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