The number format in Swiss German is like "100'000.00" (not "100,000.00"). How can I change that? I tried to change the settings in number_pipe.js from en-US to de-CH without success.
var defaultLocale: string = 'de-CH';
Is there a workaround or do I have to implement my own pipe?
The best option for me was the famous https://www.npmjs.com/package/numeral package. (he works with same logical of the
moment.js
)To install it:
npm i numeral@2.0.6
and with typesnpm i --save-dev @types/numeral@0.0.22
At your
ts
file you can use as follow:For HTML template you can create a
Pipe
like this:Additionally, for currency (and locales) a good strategy is use the package
ng2-currency-mask
for currency masks in HTML (but onts
files you may should "translate" the binded value in the model withnumeral
before save your model object.Using
ng2-currency-mask
on HTML Template:And on
ts
before save the model:https://github.com/cesarrew/ng2-currency-mask
Following is the my solution and it will help to someone.
In the html you can use as follows
Number format will change according to value of locale.
Please refer https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat for more detail.
Try using the locale-number.pipe.ts or
you could create a simple pipe based on NumeralJs to format numbers
https://github.com/adamwdraper/Numeral-js
If you only need one locale for your app, you can as of now (@angular ~2.4.0) register the locale provider in @NgModule.