我试图显示两个数字的总和,但它返回额外的零。
示例
newprice -> 174.000
added number -> 1
total should be -> 174.001
but it shows 1.740.001
代码
查看
{{(newprice + optionPrice | currency: 'Rp ' : 'symbol' : '1.0-0')}}
Controller
export class OptionsPage implements OnInit {
optionPrice = '0';
newprice: null;
constructor(
public modalController: ModalController
) { }
ngOnInit() {
this.newprice; // it comes from other page in this case is (174000)
this.optionPrice;
}
// this price comes from selected option and will be sum to "newprice" value (in this sample is 1)
onChange(value) {
console.log(value);
this.optionPrice = value;
}
}
有什么想法吗?
最佳答案
我认为它的作用就像newprice
和optionPrice
是字符串。
你可以这样做:
{{((+newprice) + (+optionPrice) | currency: 'Rp ' : 'symbol' : '1.0-0')}}
// ^ ^ this "+" operators converts strings to number
关于javascript - Angular 显示带有额外零的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57787388/