【发布时间】:2021-09-20 12:18:35
【问题描述】:
在我的 calculatePercents() 方法中,我应该得到 0% 而不是 NULL%。
在我的 console.log 中,我得到了带有值 NULL 的打印件
calculatePercents() {
this.v.global.total.amount = this.v.global.cash.amount + this.v.global.sec.amount;
console.log("Cash => " + JSON.stringify(this.v.global.total.amount));
console.log('------------------------');
this.v.global.cash.percent = (this.v.global.cash.amount / (this.v.global.cash.amount + this.v.global.sec.amount)) * 100;
console.log(" Global cash " + JSON.stringify(this.v.global.cash.percent));
this.v.global.sec.percent = (this.v.global.sec.amount / (this.v.global.cash.amount + this.v.global.sec.amount)) * 100;
console.log(" NULL ???? ==> " + JSON.stringify(this.v.global.sec.percent));
var totPercent = (this.v.global.cash.percent + this.v.global.sec.percent);
this.v.global.total.percent = totPercent;
}
请问我怎样才能得到 0 而不是 NULL。
【问题讨论】:
-
请始终显示适当的minimal reproducible example 此类问题。
-
这能回答你的问题吗? JavaScript convert NULL to 0
标签: javascript angular typescript