Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: Change decimal separator to comma

I hope I get a solution for this. I am using angular1.4.

I want to display time in decimal numbers(separated by comma because users are in Germany-Europe).

For example 5min is expected to be displayed as:

5min=(5/60)=0,08 (2 decimal places)

Then I came across this solution: AngularJS number filter. However the result appears in decimal, what can I add to this pipe filter below, to change/replace decimal to comma?

<span>{{ dr.duration/(60*60*1000) | number:2}}</span>

In case you need clarity lemme know.

like image 910
Kelvin Cayman Avatar asked Mar 01 '26 07:03

Kelvin Cayman


1 Answers

To change the separators used by the AngularJS number filter, include the appropriate locale rule set such as angular-locale_de-de.js.

There are two approaches to providing locale rules to AngularJS:

  • Pre-bundled rule sets
  • Including a locale script in index.html

For more information, see

  • AngularJS Developer Guide - Providing locale rules to AngularJS
  • AngularJS number Filter API Reference

The DEMO

<script src="//unpkg.com/angular/angular.js"></script>
<script src="//unpkg.com/angular-i18n/angular-locale_de-de.js"></script>
<body ng-app>
    <span><b>5min=(5/60)=</b>
      {{ 5/60 | number:2 }} hr (2 decimal places)
    </span>
</body>    
like image 193
georgeawg Avatar answered Mar 03 '26 20:03

georgeawg