带小数的角度货币管
我使用currencyPipe进行输入,它可以工作,但有时我需要添加小数,但使用我正在使用的代码我无法做到这一点。
this.form.valueChanges.subscribe(res => {
if(res.total_actives_amount){
this.form.patchValue({
total_actives_amount: this.currencyPipe.transform(res.total_actives_amount.replace(/\D/g, '').replace(/^0+/, ''), 'USD', 'symbol', '1.0-0')
}, {emitEvent: false});
}
})
我认为问题出在这一行:
total_actives_amount: this.currencyPipe.transform(res.total_actives_amount.replace(/\D/g, '').replace(/^0+/, ''), 'USD', 'symbol', '1.0-0')
I have my input with currencyPipe, it works, but sometimes i need to add decimals numbers, but with the code that i'm using i can't do it.
this.form.valueChanges.subscribe(res => {
if(res.total_actives_amount){
this.form.patchValue({
total_actives_amount: this.currencyPipe.transform(res.total_actives_amount.replace(/\D/g, '').replace(/^0+/, ''), 'USD', 'symbol', '1.0-0')
}, {emitEvent: false});
}
})
I think that the problem is this line:
total_actives_amount: this.currencyPipe.transform(res.total_actives_amount.replace(/\D/g, '').replace(/^0+/, ''), 'USD', 'symbol', '1.0-0')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
货币管道内的转换方法具有以下参数:
digitsInfo 采用以下格式:
{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}
您为digitsInfo 指定的值是
1.0-0
minIntegerDigits = 1
minFractionDigits = 0
maxFractionDigits = 0
显示您必须更改的十进制数字
minFractionDigits
和maxFractionDigits
为大于 0 的数字例如
1.1-3
这将显示至少一位小数数字且最多 3 位小数
参考 angular.io/currency
The transform method inside currency pipe has the following parameters:
The digitsInfo takes the following format:
{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}
the value you specified for the digitsInfo is
1.0-0
minIntegerDigits = 1
minFractionDigits = 0
maxFractionDigits = 0
to display decimal numbers you have to change
minFractionDigits
and themaxFractionDigits
to a larger number than 0for example
1.1-3
this will show at least one decimal number and at most 3 decimal numbers
reference angular.io/currency