使用管道输入数字11位小数不允许数字> 999

时间:2019-03-23 16:37:37

标签: angular pipe decimal html5-input-number

999.12345678901可以工作,但是任何> = 1000的值为NaN(在控制台中发出警告)并将输入设置为0。我在输入的onBlur中使用此Pipe。

   @Pipe({
      name: 'rExact'
   })
   export class rExactPipe extends DecimalPipe {
        transform(value: number): any {
           if(isNaN(value))
               return null;

           return super.transform(value, "1.2-11");  
        }
  }

这是onblur事件:

this.selected.UnitPrice = +new rExactPipe(this.numberLocale).transform(this.selected.UnitPrice);

输入数字字段的绑定方式如下:[(ngModel)] =“ selected.UnitPrice”

因为js是64位的,所以所有数字最多可以浮15位。我在做什么错了?

1 个答案:

答案 0 :(得分:2)

问题在于,DecimalPipe在成千上万的{{​​1}}符号后面添加了,,在您的代码中,这里的小加号1,000将结果转换回数字。这个逗号使它不可解析,结果您会得到NaN。要解决视图问题,只需删除加号即可;如果需要使用此值,请在不使用管道的情况下使用

相关问题