The formatting rules can be applied by the following pipes in views:
<div>{{ height | toNumber }}</div>
<div>{{ rate | toPercent }}</div>
<div>{{ [ price, 'EUR' ] | toCurrency }}</div>
<div>{{ now | toDatetime }}</div>
The toNumber
, toPercent
, toCcurrency
and toDatetime
pipes can bes used
with parameters as well:
<div>{{ height | toNumber:'maxfd=2' }}</div>
<div>{{ rate | toPercent:'minfd=1' }}</div>
<div>{{ [ price, 'EUR' ] | toCurrency:'minsd=2' }}</div>
<div>{{ now | toDatetime:'ds=medium;ts=medium' }}</div>
The currency pipe has an alternate version toCcy
that can be applied to a
number value. E.g. having the following model:
const product = {
name: 'Milky Way yogurt 200g',
price: 2.25,
curreny: 'USD'
};
The product price can be displayed in the following way:
<div>{{ product.price | toCcy: product.currency }}</div>
The currency localization parameters can be added to the currency code by separated a vertical bar (`|``) character:
<div>{{ product.price | toCcy: `${ product.currency }|minsd=2` }}</div>