【问题标题】:i want to sum three fields which is get through database我想总结三个通过数据库获得的字段
【发布时间】:2020-05-14 20:55:53
【问题描述】:
page.ts
price = 300,residential_package = 120, accompany = 1335;
this.delegates_total = this.price + this.residential_package + this.accompany;
result shows 3001201335
我想添加这些字段的值,但它没有给我正确的结果请告诉我哪里出错了,谢谢你的帮助
【问题讨论】:
标签:
html
css
ionic-framework
angular7
ionic4
【解决方案1】:
使用Number()转成数字再使用+;
或者您可以使用+ 转换为像+this.price 这样的数字;
price = 300,residential_package = 120, accompany = 1335;
this.delegates_total = Number(this.price) + Number(this.residential_package) + Number(this.accompany);
【解决方案2】:
在您的情况下,您将连接 3 个字符串
用类型声明你的字段
price:number=300
residential_package:number=120
accompany:number=1335