Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How check if a string is nan (not a number) ?

Asked by 6 years ago

The title explain everything.

I tried this :

local V = "145"
    if (V) == "number" then
        print("V is a number")
    else
        print("V is not a number")
    end
end)
0
I think you meant to use type or typeof ? User#5423 17 — 6y

2 answers

Log in to vote
0
Answered by
Simnico99 206 Moderation Voter
6 years ago
Edited 6 years ago

You can use type() to get the type of a value.

local V = 145

    if type(V) == "number" then
        print("V is a number")
    else
        print("V is not a number")
    end
0
worked thanks ! xJathur95x 129 — 6y
0
Np :P Simnico99 206 — 6y
0
You guys make no sense. Downvoting something that works? You guys have brain damage. DeceptiveCaster 3761 — 5y
Ad
Log in to vote
2
Answered by 6 years ago

You can use tonumber() to check if a string can be converted to a number.

local V = "145"
    if tonumber(V) then
        print("V is a number")
    else
        print("V is not a number")
    end
end)
0
Thanks xJathur95x 129 — 6y
0
That's really stupid. DeceptiveCaster 3761 — 5y
0
Use type(). DeceptiveCaster 3761 — 5y
0
tonumber is faster and requires less typing killer08932 149 — 4y

Answer this question