Reputation: 21
Let's consider in Flutter we are showing the number in language English. When the user changes the language to Hindi or any other Indian language, the number should be displayed as per the language, not in English.
Upvotes: 1
Views: 40
Reputation: 81
To use localized numbers in Flutter, you can use the NumberFormat class from the intl package. This class provides methods for formatting and parsing numbers based on the user's locale.
double number = 123456.789;
List<String> locales = ['en', 'de', 'fr', 'hi', 'ja'];
for (String locale in locales) {
String formattedNumber = NumberFormat.decimalPattern(locale).format(number);
print('Locale [$locale] : $formattedNumber');
}
This will return -
Locale [en]: 123,456.789
Locale [de]: 123.456,789
Locale [fr]: 123 456,789
Locale [hi]: 1,23,456.789
Locale [ja]: 123,456.789
Upvotes: 2