0👍
✅
It sounds like the problem is that banknote.amount
is a string rather than a number.
If possible you should fix the values in banknotes
so that the amount
values are all numbers.
If not, you could coerce to a number when performing the addition:
addCashAmount(banknote) {
this.cash_amount += +banknote.amount
},
Here I’ve used a unary +
to perform the coercion. If you prefer a different method, such as calling Number
, that should work too:
addCashAmount(banknote) {
this.cash_amount += Number(banknote.amount)
},
You should also check that the initial value of cash_amount
is the number 0
and not the string '0'
or the empty string ''
as that would cause a similar problem.
Source:stackexchange.com