1

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

1
  • 1
    One of total_without_discount, total_taxs or total_discount returns either undefined or NaN. Without a proper minimal reproducible example we cannot tell you exactly what is going on besides: Make sure that they do not return that. Commented Feb 23, 2019 at 18:59

1 Answer 1

2

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);
},
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.