Hi sumaiya! How are you doing?
In AS3 or AS2? in AS2 there's no integer type, in AS3 there is the new "int" data type, though if you ask a typeof, even if it is an integer, it still will return "number" as the type.
In AS3, however, you can use the "is" operator as follows:
trace(thenumber is int);
that will trace true if "thenumber" is an integer, and false if it isn't. You also have the new datatype uint, that covers only the positive integers (int covers both, positive and negative integers):
trace(thenumber is uint);
Anyway, in AS2 there's no int or uint data type, so I think one thing you could do is convert it to a string and search for a dot, if there's a dot it is not an integer. You can make it a function like this:
-
-
function isInt(n:Number):Boolean {
-
return !(n.toString().indexOf(".") != -1);
-
}
-
-
trace(isInt(3));
-
//traces: true;
-
-
trace(isInt(2.4));
-
//traces: false;
-
-
Or prototype it to the Number object:
-
-
Number.prototype.isInt = function():Boolean {
-
return !(this.toString().indexOf(".") != -1);
-
}
-
-
var somevar:Number = 1;
-
-
trace(somevar.isInt());
-
//traces: true;
-
-
var somevar:Number = 0.25;
-
-
trace(somevar.isInt());
-
//traces: false;
-
Best regards!
The_Nephilim
How can I find if a variable is integer in flash ??