开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜