Reputation: 911
I am trying to format the number according to selected currency without translating it. For example the
Text(NumberFormat.simpleCurrency(
locale: 'bn_BN',
).format(123456.78));
outputs
১,২৩,৪৫৬.৭৮৳
I want the format but not on the locales language. How do i get it to look like this instead -
1,23,456.78 BDT or 1,23,456.78 ৳
Is there a way to achieve this
P.S. I just need the thousands seperator or grouping to be what the currency default is for example BDT grouping is XX,XX,XXX first comma after thousand then comma after each 2 digits. This is something the NumberFormat does on its own but unfortunately only when u pass in locale.
Upvotes: 1
Views: 1911
Reputation: 3407
You can define a custom NumberFormatter somewhere in your code (assuming that you will use it in different parts of your application) and format() numbers using it:
final myFormatter = new NumberFormat.currency(
name: 'BDT',
decimalDigits: 2,
customPattern: '#,##,##0.00 \u00A4',
);
Text(myFormatter.format(12345678.01)),
This will result in: 1,23,45,678.01 BDT
Upvotes: 1
Reputation: 2758
Check out this answer in another question:
https://stackoverflow.com/a/61530490/6704033
The last example is the one you want to use with your format #,##,##0.00
I don't think you want to provide your BN locale because that's whats causing the localised numbers. Maybe leave this default or set to 'en'.
var myNumberFormat = NumberFormat('#,##,##0.00', 'en');
var myString = '${myNumberFormat.format(123456.78} ৳';
Upvotes: 0