0

我试图显示两个数字的总和,但它返回额外的零。

样本

newprice -> 174.000
added number -> 1
total should be -> 174.001

but it shows 1.740.001

代码

view

{{(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;
  }
}

任何想法?

4

1 回答 1

2

newprice我认为它的行为就像optionPrice是字符串。

你可以这样做:

{{((+newprice) + (+optionPrice) | currency: 'Rp ' : 'symbol' : '1.0-0')}}
//  ^             ^    this "+" operators converts strings to number
于 2019-09-04T11:29:40.543 回答