How to hide currency symbol in angular currency pipe
Asked Answered
S

4

17

I'm trying to use Angular currency pipe and I wanted to remove the currency symbol all together from the formatted number, but it seems there is no option to do that. So is there any easy way to achieve this without writing a custom pipe for it?

Scrivenor answered 4/7, 2019 at 16:38 Comment(2)
Maybe use this: angular.io/api/common/DecimalPipeQualm
@R.Richards Oh, I was so lost in achieving this with currency pipe, I didn't pay attention to other pipes that would do this. Thanks.Scrivenor
S
17

As @R.Richards mentioned, I ended up using the number pipe:

{{ 50000 | number }} <!-- output: 50,000 -->
Scrivenor answered 4/7, 2019 at 16:56 Comment(0)
A
43

Just send the arguments empty:

price | currency:'':''
Aghast answered 4/7, 2019 at 16:54 Comment(2)
It won't work. The number gets formatted with the dollar sign!Scrivenor
Thanks, this works on me. This code is only remove the currency symbolChloromycetin
S
17

As @R.Richards mentioned, I ended up using the number pipe:

{{ 50000 | number }} <!-- output: 50,000 -->
Scrivenor answered 4/7, 2019 at 16:56 Comment(0)
M
4

Hope this example could help.

{{ 0001234.012 | currency:' ':'symbol':'0.0-1' }}  <!-- 1,234 -->
{{ 0001234.012 | currency:' ':'symbol':'0.1-1' }}  <!-- 1,234.0 -->
{{ 0001234.012 | currency:' ':'symbol':'0.0-2' }}  <!-- 1,234.01 -->
{{ 0001234.012 | currency:' ':'symbol':'0.2-2' }}  <!-- 1,234.01 -->

{{ 123 | currency:' ':'symbol':'5.0-0' }}          <!-- 00,123 -->
{{ 123 | currency:' ':'symbol':'4.0-0' }}          <!-- 0,123 -->
{{ 123 | currency:' ':'symbol':'3.0-0' }}          <!-- 123 -->
Maurine answered 14/4, 2022 at 3:13 Comment(0)
J
2

Another option is to set this globally:

import { DEFAULT_CURRENCY_CODE, NgModule } from '@angular/core';

@NgModule({
  ...
  providers: [
    { provide: DEFAULT_CURRENCY_CODE, useValue: '' },
  ],
  ...
})

Example:

<div>{{ 20124.56789 | currency }}</div>   <!-- output: 20,124.57 --> 
Josh answered 30/9, 2022 at 13:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.