2 years ago

#45888

test-img

angie

How to display numbers in different formats depending on the user's PC language settings in Angular

I want to display numbers in different formats depending on the user's PC language settings.

Say if my PC is set in English the number 12.3 will be displayed as 12.3 and if my PC is set in Italian the number 12.3 will be displayed as 12,3.

I tried using myNumber.toLocaleString() but it is not working as expected.

I also tried using the LOCALE_ID and set the value in providers in main.ts file :

{ provide: LOCALE_ID, useValue: navigator.language }

but navigator.language returns the language of the browser, I need the language of the user's OS.

Is there any other way around this?

angular

typescript

locale

0 Answers

Your Answer

Accepted video resources