我在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/ –