'Force all textview in app to display numbers in en-us format android

I have an issue when the user changes his phone to Arabic and reopen my application the numbers are in Arabic, is there a way to force all the app to convert all textview to accept Locale.US? maybe set the style same as font text?



Solution 1:[1]

You can use NumberFormat class which offers to format of numbers based on a given Locale. Given code in Kotlin

val number = 10
val formatter = NumberFormat.getInstance(Locale.US)
text_view.text = formatter.format(number)

Or, in case if you want to change number as per to its currency formatting, you can do the same with the help of same class.

val formatter = NumberFormat.getCurrencyInstance(Locale.US)
text_view.text = formatter.format(number)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anshul1507