Angular 2:decimalPipe结果 - >转换回数字?

时间:2018-04-03 09:51:24

标签: angular

<input>格式化的this.decimalPipe.transform(...)元素中的数字 用户更改了值,然后我需要从input元素中获取此字符串值并将其转换回数字以进行进一步操作。 如何进行反向操作 - 将字符串从decimalPipe结果转换回数字?

2 个答案:

答案 0 :(得分:0)

尝试

let number = parseFloat(inputFiled.Value);

答案 1 :(得分:0)

对我来说最好的选择是使用ng2-currency-mask指令进行简洁编码。

<input currencyMask [(ngModel)]="value" [options]="{ prefix: 'R$ ', thousands: '.', decimal: ',', precision: 2 }"/>