What do you mean by "a number"?Checking if a number is an integer is as simple as going through every character in the string and making sure that it's in 0123456789.Checking if a number is a float can be done by using some mathematical functions that would screw up when not receiving floats (and thus invalidate it) or by some state-based string checking.
I want to check if it's an integer or a float.
Checking if a number is an integer is as simple as going through every character in the string and making sure that it's in 0123456789.
Whatu srsisInt(%string)
Haven't tested this extensively, but it should work in most cases.if ( %value $= "0" || %value $= %value * 1 )
function isNumber(%val){ return (%val $= %val * 1);}
You shouldn't need the %value $= "0" bit, because "0" $= "0" * 1 evaluates to true.I think this is what most people use:Code: [Select]function isNumber(%val){ return (%val $= %val * 1);}
function isNumber(%val){ return %val $= (%val + 0);}function isInt(%val){ return %val $= (%val << 0);}
That won't work with say, "1234567654321" though. Or in other words any number over 1 million not in scientific notation.
So how would I do it with a for statement?
I'm not quite sure what you mean. There is no difference between calling a function or using an if statement outside or inside of a for statement.
I want to know how to find if a string is a number using a for statement because that seems the only way that can handle over a million.
Code: [Select]function isInt(%val){ return %val $= (%val << 0);}
function isInt(%val){ return %val $= (%val << 0);}