Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set locale for numbers in angular 2.0

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?

like image 675
surfspider Avatar asked Jun 07 '16 16:06

surfspider


People also ask

What is locale in angular?

Angular uses the Unicode locale identifier (Unicode locale ID) to find the correct locale data for internationalization of text strings. Unicode locale ID. A locale ID conforms to the Unicode Common Locale Data Repository (CLDR) core specification.

What is the default value of maxFractionDigits while using the DecimalPipe?

Default is 0. maxFractionDigits : The maximum number of digits after the decimal point. Default is 3.

What is decimal pipe in angular?

The DecimalPipe is used to format a value/ number as per the required decimal digits and locale information. The name of the pipe is number.


1 Answers

If you only need one locale for your app, you can as of now (@angular ~2.4.0) register the locale provider in @NgModule.

@NgModule({
    ...
    providers: [
        {provide: LOCALE_ID, useValue: "de-CH"}
    ]
})
export class AppModule {}
like image 187
mikevinmike Avatar answered Oct 05 '22 12:10

mikevinmike