0
我正在爲我的班級製作稅務計算器,但我無法弄清楚如何將小數乘以整數。我必須乘以0.13。這裏是我的代碼Actionscript 3中的小數乘以
var amount:Number;
var hst:int;
amount_txt.restrict = "0-9";
calculate_btn.addEventListener(MouseEvent.CLICK, calculate);
function calculate(event:MouseEvent):void
{
amount = Number(amount_txt.text);
total_txt.text = "You have spent a total of " + String(Math.round((amount * hst)) + "$")
}
我很樂意幫助快速,因爲它是明天到期。我很抱歉如果這裏的格式不正確,但我向你保證實際的程序是正確的。謝謝
十進制數給**預期輸出**的例子從兩個輸入值(全VS分數)。所以你的'金額= 0.13',但'hst'多少? 「int」的默認值爲零,所以現在你的代碼正在執行'0.13 x 0',它給出了正確的'0'。問題是什麼? –
你的'hst'是int,所以它不能存儲0.13。使它成爲'數字'和0.13的東西,應該這樣做。 – Vesper
@Vesper也許'hst'是int型的,因爲它是神祕的_whole number_?然後再次,他們限制文本數量爲'0-9',爲什麼不使用'amount = int(amount_txt.text);'?我只希望Asker知道'number'用於處理分數,但是'int'只處理整數(小數點被忽略)。 –