在Actionscript 3中乘以小数

时间:2017-01-27 01:18:02

标签: actionscript-3 flash

我正在为我的课程制作税务计算器,但我无法弄清楚如何将整数乘以小数。我必须将整数乘以0.13。这是我的代码

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)) + "$") 
}

我很乐意帮助他们,因为它将在明天到期。如果这里的格式不正确,我很抱歉,但我向你保证实际程序是正确的。谢谢

1 个答案:

答案 0 :(得分:1)

原因是您的HST不是Number而是int。为了使其成为十进制数,您必须将其更改为Number

var amount:Number;
var hst:Number;

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)) + "$") 
}