Check for whole number in AS 3
How can I check for a whole number in AS 3?
Example:
for (var i:int = 0; i < thumbs.length(); i++)
{
if((i 开发者_运维问答/ this.thumbsRow) === wholeNumber)
}
if(int(k) === k)
trace("whole number");
else
trace("float");
Try the modulo operator:
var isWhole:Boolean = foo % 1 == 0;
trace("Is whole number: " + isWhole);
Where 'foo' is the number you're checking. Modulo gives you the remainder of dividing the first number by the second number. For any whole number, there would be no remainder.
精彩评论