I have to display Euro currency like this : 583 €
.
But with this code:
{{ price | currency:'EUR':true }}
I get €583
, is there any option in Angular core to move the symbol to right? A lot of european countries use the symbol at the right (France, Germany, Spain, Italy).
Provide LOCALE_ID was not a solution because my application is in english but shows the currency with french locale. So if I set my LOCALE_ID to
fr-FR
, all my dates are in french, which is not acceptable.So I simply choose the decimal pipe then I add the symbol at the end.
The problem here, if the number is not defined, you will end up with only the symbol. To resolve that issue, I've created a not empty pipe :
And use it like this :
Do it like this:
No need for extra pipes, it uses the default currency pipe
Since Angular2 RC6 version you can set default locale directly in your app module (providers):
Afterwards the currency pipe should pick up the locale settings and move the symbol to right:
This is working (angular 6) on html side:
and on typescript side:
123.456,79 €
Currency pipe format is controlled by the current locale rules. See also Using Pipes:
Under the hood
CurrencyPipe
delegates formatting tonew Intl.NumberFormat(locale, options).format(num);
.Intl.NumberFormat Using options:
In other words, formatting currencies with
CurrencyPipe
involves:Honestly, I couldn't find any in-built way to do it. So created custom pipe called split.
working Demo: http://plnkr.co/edit/KX7hfaV2i7CX2VFobM8R?p=preview