Reputation: 1
I'm making a tax calculator for my class and I can't figure out how to multiply a whole number with a decimal. I have to multiply the whole by 0.13. Here's my code
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)) + "$")
}
I would appreciate help quick, as it is due tomorrow. I apologize if the formatting on here is incorrect, but I assure you on the actual program it is correct. Thanks
Upvotes: 0
Views: 202
Reputation: 1209
The reason is that your HST is not a Number
but an int
. In order to make it a decimal number you have to change it as a 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)) + "$")
}
Upvotes: 1