isNumber("2.4.6")
isNumber(".")
While reading into this I found something interesting:
$ echo(10291059192+0);
1.70112e+009
$ echo("10291059192"+0);
1.02911e+010
loving fascinating
$ echo("2e24");
2e24
$ echo("2e24"+0);
2e+024
$ echo("2e24" > 999999);
1
help i'm so confused
function isNumeric(%i)
{
if(%i <= 999999 && %i >= -999999)
{
// Fast solution
return %i $= %i * 1;
} else {
// Slow solution
%dot = 0; // Track if period present
%sci = 0; // Track if scientific notation present
for(%j=0;%j<strLen(%i);%j++)
{
%c = getSubStr(%i,%j,1);
if(%c $= "-")
{
if(%j != 0)
return false; // Negative not the first character
continue;
}
if(%c $= ".")
{
if(%dot || %j == 0)
return false; // Multiple periods or nothing before the period
else
%dot = 1;
continue;
}
if(%c $= "e")
{
if(%sci != 0)
return false; // Multiple Es present
else
%sci = -1;
continue;
}
if(%c $= "+")
{
if(%sci != -1)
return false; // + is not part of e+ scientific notation
else
%sci = 1;
continue;
}
if(%sci == -1 || strPos("0123456789",%c) == -1)
return false; // An E was present without a + or the current character is not a number
}
if(%sci == -1)
return false; // Last character was an E. Sneaky bastard
return true; // Gamut has been run, nothing returned, ergo it is fine
}
}
For numbers in the range of -999999 to 999999, uses the fast, math-based solution. For numbers which will error out with that solution (sometimes) due to scientific notation, uses a string parser to match if it's valid scientific notation (or an integer outside that range that is still not scientific notated).
Can't find anything it matches that it shouldn't, or anything it doesn't match that it should