带小数的角度货币管

发布于 2025-01-13 07:23:51 字数 562 浏览 3 评论 0原文

我使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧时浪漫 2025-01-20 07:23:51

货币管道内的转换方法具有以下参数:

transform(
   value: string | number,
   currencyCode: string,
   display: string | boolean,
   digitsInfo: string,
   locale: string
) {...}

digitsInfo 采用以下格式:

{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}

您为digitsInfo 指定的值是 1.0-0

minIntegerDigits = 1

minFractionDigits = 0

maxFractionDigits = 0

显示您必须更改的十进制数字minFractionDigitsmaxFractionDigits 为大于 0 的数字

例如

1.1-3

这将显示至少一位小数数字且最多 3 位小数

参考 angular.io/currency

The transform method inside currency pipe has the following parameters:

transform(
   value: string | number,
   currencyCode: string,
   display: string | boolean,
   digitsInfo: string,
   locale: string
) {...}

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 the maxFractionDigits to a larger number than 0

for example

1.1-3

this will show at least one decimal number and at most 3 decimal numbers

reference angular.io/currency

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文