i have code in vue js
totalPrice() {
return (this.carts || []).reduce(function (items, data) {
return items parseFloat(data.games.price * data.quantity)
}, 0)
}
but the result i dont get decimal number like 400.000
i change the parseFloat to parseInt but nothing happen
CodePudding user response:
Do not parse your number, and then try to add that string to your accumulator, in your reducer.
If you want to print a numeric string with 3 decimal places:
totalPrice() {
return (this.carts || []).reduce(function (items, data) {
return items (data.games.price * data.quantity)
}, 0.0)
}
const str = totalPrice().toFixed(3)
or
totalPriceString() {
return totalPrice().toFixed(3)
}