Author Topic: isNumeric  (Read 757 times)

How do I tell if a number is numeric(forgot)

if(%n $= %n*1)
   echo("It's a number.");

if(%n $= %n*1)
   echo("It's a number.");
Oh, code especially works when it's not quoted out.



For fun/simplicity, I shall put it into function form.

function isNumeric(%val)
{
   if(%val $= %val*1)
      return 1;
   else
      return 0;
}

For fun/simplicity, I shall put it into function form.

function isNumeric(%val)
{
   if(%val $= %val*1)
      return 1;
   else
      return 0;
}

Or just

function isNumeric(%val)
{
     return (%val $= %val*1);
}

:/


I'm not sure if it's a default function but isInt()


mFloatLength(%num,3)
returns the number to 3 decimal places or 0 if it's non-numeric

mFloatLength(%num,3)
returns the number to 3 decimal places or 0 if it's non-numeric

Wouldn't it return 0 for 0 though, even though 0 is a number?

mFloatLength("asdfg",0);
Returns 0

mFloatLength(0, 0);
returns 0

mFloatLength("asdfg",0);
Returns 0

mFloatLength(0, 0);
returns 0

("asdfg" $= "asdfg"*1)
returns 0

(0 $= 0*1)
returns 1

Yeah, but if you're using a user-entered number somewhere it's quicker and easier to just take it as zero rather than add a million error messages that are just annoying about it. In most cases it'll just be "You gave X $0" and makes no difference at all.