Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度显示带有额外零的数字_Javascript_Angular - Fatal编程技术网

Javascript 角度显示带有额外零的数字

Javascript 角度显示带有额外零的数字,javascript,angular,Javascript,Angular,我试图显示两个数字的和,但它返回额外的零 样品 代码 查看 {{(newprice + optionPrice | currency: 'Rp ' : 'symbol' : '1.0-0')}} 控制器 export class OptionsPage implements OnInit { optionPrice = '0'; newprice: null; constructor( public modalController: ModalController )

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

样品 代码
查看

{{(newprice + optionPrice | currency: 'Rp ' : 'symbol' : '1.0-0')}}
控制器

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

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

你可以这样做:

{{((+newprice) + (+optionPrice) | currency: 'Rp ' : 'symbol' : '1.0-0')}}
//  ^             ^    this "+" operators converts strings to number

为什么你访问你在组件中定义的变量,在
OnInit
钩子中,甚至没有对变量做任何操作?这是模态,模态一弹出我就需要值,这就是为什么我很确定这不是两个整数相加的方式,除非你为两个整数指定了单位。(在这种情况下,我想你是想在美元中增加美分-请在发布之前检查你的逻辑)但你实际上并没有将变量的值记录到控制台或任何东西。@Edric dude,目前我在获取我需要的2个值方面没有问题。我的问题是将其作为真实金额返回。你知道吗?为什么你在
OnInit
hook中访问你在组件中定义的变量,而不对变量做任何操作?这是模态,模态一出现我就需要值,这就是为什么我很确定这不是两个整数相加的方式,除非你为两个整数指定了单位。(在这种情况下,我想你是想在美元中增加美分-请在发布之前检查你的逻辑)但你实际上并没有将变量的值记录到控制台或任何东西。@Edric dude,目前我在获取我需要的2个值方面没有问题。我的问题是将其作为真实金额返回。有什么想法吗?很乐意帮忙:)请不要担心。很乐意帮忙:)请不要担心。