AS3 | Devide to float number

时间:2014-02-07 14:53:17

标签: actionscript-3 actionscript numbers

有没有办法除以10并检查结果是否为浮点数?

我的车是:

var X:int=40;
var Y:Number=0;
//I want to Y get 4, 
//but when X is 45, Y get 0

2 个答案:

答案 0 :(得分:2)

if( X%10 == 0 )
    Y = X/10;
else
    Y = 0;

答案 1 :(得分:1)

试试这个:

var X:int = 45;
var Y:Number = (X / 10).toString().indexOf(".") == -1 ? X / 10 : 0;

更长的形式:

var X:int = 45;
var Y:Number = 0;
var Z:String = (X / 10).toString(); 

if (Z.indexOf(".") == -1) {
    Y = X / 10;
} else {
    Y = 0;
}