我在Flash中有两个按钮。目标是当你点击一个时,计数器将增加1.9,如果你点击另一个,它将减少1.9。但是,当您尝试将数字增加/减少1.9时,点击几下后,数学会稍微偏离。该数字应该是一位或两位小数。Actionscript 3计算器差异
var count1:uint = 0;
var unit:Number = 0;
add1_btn.addEventListener(MouseEvent.CLICK, add1);
take1_btn.addEventListener(MouseEvent.CLICK, take1);
counter1.text = '0';
function add1(event:Event):void
{
count1++;
counter1.text = count1.toString();
unit+= 1.9;
var unitRound= int((unit)*10)/10;
units.text = unitRound.toString();
}
function take1(event:Event):void
{
count1--;
counter1.text = count1.toString();
unit-= 1.9;
var unitRound= int((unit)*10)/10;
units.text = unitRound.toString();
}
为了记录,浮点问题不是Flash/ActionScript特定的。更多关于这个问题在http://floating-point-gui.de/ –