linkCurrencyPipe
| npm Package | @angular/common |
|---|---|
| Module | import { CurrencyPipe } from '@angular/common'; |
| Source | common/src/pipes/number_pipe.ts |
| NgModule | CommonModule |
Formats a number as currency using locale rules.
linkHow To Use
number_expression | currency[:currencyCode[:display[:digitInfo[:locale]]]]
linkDescription
Use currency to format a number as currency.
currencyCodeis the ISO 4217 currency code, such asUSDfor the US dollar andEURfor the euro.-
displayindicates whether to show the currency symbol or the code.code: use code (e.g.USD).symbol(default): use symbol (e.g.$).symbol-narrow: some countries have two symbols for their currency, one regular and one narrow (e.g. the canadian dollar CAD has the symbolCA$and the symbol-narrow$).- boolean (deprecated from v5):
truefor symbol and false forcodeIf there is no narrow symbol for the chosen currency, the regular symbol will be used.
digitInfoSeeDecimalPipefor detailed description.localeis astringdefining the locale to use (uses the currentLOCALE_IDby default)
linkExample
@Component({
selector: 'currency-pipe',
template: `<div>
<!--output '$0.259'-->
<p>A: {{a | currency}}</p>
<!--output 'CA$0.26'-->
<p>A: {{a | currency:'CAD'}}</p>
<!--output 'CAD0.26'-->
<p>A: {{a | currency:'CAD':'code'}}</p>
<!--output 'CA$0,001.35'-->
<p>B: {{b | currency:'CAD':'symbol':'4.2-2'}}</p>
<!--output '$0,001.35'-->
<p>B: {{b | currency:'CAD':'symbol-narrow':'4.2-2'}}</p>
<!--output '0 001,35 CA$'-->
<p>B: {{b | currency:'CAD':'symbol':'4.2-2':'fr'}}</p>
</div>`
})
export class CurrencyPipeComponent {
a: number = 0.259;
b: number = 1.3495;
}