Format a number
-
Hi,
is there in Mango a global setup to format number and date output?
Example: "{{points | maSum:'value' | number:1}}" = 3,100.2 into 3.100,2...Thanks,
Ralf -
Global, no. You have to do it using filters as you wrote.
-
Hi Jared,
and how to do it using the filter :) ?
-
Ah sorry! I didn't notice the difference in formatting. I thought you were asking how to globally format all numbers to 1 decimal place.
To change to European number formatting you need to load a different locale into AngularJS. You will have to do this manually at the moment but I will make this easier for the next UI module release (I'll try and make it use the server or user locale).
To change it for the time being (this will be a site-wide change, it will affect all users) add the following user module -
define([ 'angular', 'require', 'https://cdnjs.cloudflare.com/ajax/libs/angular-i18n/1.6.6/angular-locale_es.js' ], function(angular, require) { 'use strict'; var userModule = angular.module('userModule', ['maUiApp', 'ngLocale']); return userModule; }); // define
Change the locale file to whichever locale you desire, the list of different locales is here -
https://cdnjs.com/libraries/angular-i18n/1.6.6
You can also save the file to your file store and load it from there if users do not have internet access.Changing the locale will affect the built in AngularJS filters such as number, date and currency. Try these out:
{{10000.235 | number}} {{1511804829000 | date}} {{3545.22 | currency}}
-
It works, thank you Jared!
If it is possible it would be more flexible to define this in the user settings...
-
@ralf Yeah like I said I'll make it use the user's locale. I wont make it possible to define number formats in the user settings however if this is what you meant.