Reputation: 1101
hi i have this vuejs2 code
totals() {
this.total = 0;
console.log(this.total_without_discount);
console.log(this.total_taxs);
console.log(this.total_discount);
this.total += this.total_without_discount;
this.total += this.total_taxs;
this.total += this.total_discount;
return Number(this.total).toFixed(this.comma);
},
now when i get the result back i gat Nan
all these functions are in computed
how can i sum the values inside totals function and return it back
thanks
Upvotes: 1
Views: 97
Reputation: 18197
Use parseInt or parseFloat, depending on the data type and precision needed:
totals() {
this.total = 0;
this.total += parseFloat(this.total_without_discount);
this.total += parseFloat(this.total_taxs);
this.total += parseFloat(this.total_discount);
return parseFloat(this.total).toFixed(this.comma);
},
Upvotes: 2