我想对通过数据库获取的三个字段求和
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
我想添加这些字段值,但它没有给我正确的结果请告诉我哪里出了问题,谢谢你的帮助
使用Number()
转换为数字然后使用+
;
或者您可以使用 +
转换为数字 +this.price
;
price = 300,residential_package = 120, accompany = 1335;
this.delegates_total = Number(this.price) + Number(this.residential_package) + Number(this.accompany);
在你的例子中,你连接了 3 个字符串
使用 type
声明您的字段
price:number=300
residential_package:number=120
accompany:number=1335
page.ts
price = 300,residential_package = 120, accompany = 1335;
this.delegates_total = this.price + this.residential_package + this.accompany;
result shows 3001201335
我想添加这些字段值,但它没有给我正确的结果请告诉我哪里出了问题,谢谢你的帮助
使用Number()
转换为数字然后使用+
;
或者您可以使用 +
转换为数字 +this.price
;
price = 300,residential_package = 120, accompany = 1335;
this.delegates_total = Number(this.price) + Number(this.residential_package) + Number(this.accompany);
在你的例子中,你连接了 3 个字符串 使用 type
声明您的字段price:number=300
residential_package:number=120
accompany:number=1335