angular.js – decimal numbers in European notation

All we need is an easy explanation of the problem, so here it is.

In Angular you can use the currency filter to format a number, like like this:

{{service.price | currency: "€ "}}

the standard output is

€ #,##0.00

How can the output be:

€ #.##0,00

(European notation)

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

Angular supports i18n Standard for location | globalization | internationalization. When it comes to number formatting Angular relies on $locale service and more specifically on the property NUMBER_FORMATS.

The currency symbol by itself will not change the numbering formatting unless you change the ‘location’.

Here is the list of locations currently supported by angular:

http://cdnjs.com/libraries/angular-i18n/

Here is an example on how to support german locale:

<html ng-app>
 <head>

   <script src="angular.js"></script>
   <script src="i18n/angular-locale_de-de.js"></script>

 </head>
</html>

If you want to dig more into it you can search for NUMBER_FORMATS in any of the CDNs provided above and you will find what angular will use to format your numbers, this is an example:

"NUMBER_FORMATS": {
    "CURRENCY_SYM": "\u20ac",
    "DECIMAL_SEP": ",",
    "GROUP_SEP": ".",
...

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply