Reputation: 5
I want to round up the result of this to 2 decimal places. I already tried Math.floor*(Math.pow (1.02,7)*100)/100 But I get 1,150 instead of 1,148.69 - the answer I aim to be returned.
A snippet of my code atm:
function money (amount) {
return amount*(Math.pow (1.02,7))
}
money(1000);
Upvotes: 0
Views: 124
Reputation: 10627
Here is how .toFixed()
is used:
function money(amount){
return (amount*Math.pow(1.02, 7)).toFixed(2);
}
console.log(money(1000));
Upvotes: 0
Reputation: 921
function money (amount) {
return Math.round(((amount*(Math.pow (1.02,7))) * 100)) / 100;
}
console.log(money(1000));
This will give the
Upvotes: 1
Reputation: 5014
You can use toFixed
to round to a certain decimal
function money (amount) {
return (amount*(Math.pow (1.02,7))).toFixed(2)
}
console.log(money(1000))
Upvotes: 3