Search code examples
htmlcssionic-frameworkangular7ionic4

i want to sum three fields which is get through database


page.ts

 price = 300,residential_package = 120, accompany = 1335;
 this.delegates_total =   this.price + this.residential_package + this.accompany;

result shows 3001201335

I want to add these fields value but it doesn't give me correct result please tell me where m going wrong and thank you for your help


Solution

  • use Number() to convert to number and then use +;

    Or you can use + to convert to number like +this.price;

    price = 300,residential_package = 120, accompany = 1335;
    this.delegates_total =   Number(this.price) + Number(this.residential_package) + Number(this.accompany);