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?
Asked
Active
Viewed 1.8k times
13

Sinandro
- 2,426
- 3
- 21
- 36
-
4Maybe use this: https://angular.io/api/common/DecimalPipe – R. Richards Jul 04 '19 at 16:42
-
@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. – Sinandro Jul 04 '19 at 16:54
4 Answers
36
Just send the arguments empty:
price | currency:'':''

JuanF
- 756
- 1
- 6
- 12
-
3
-
3Thanks, this works on me. This code is only remove the currency symbol – kursat sonmez Dec 03 '19 at 08:29
16
As @R.Richards mentioned, I ended up using the number
pipe:
{{ 50000 | number }} <!-- output: 50,000 -->

Sinandro
- 2,426
- 3
- 21
- 36
2
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 -->

JJon Hsieh
- 21
- 2
0
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 -->

tbdrz
- 1,811
- 2
- 12
- 30