3

I was able to get a number in currency format with the following:

final myLocale = Localizations.localeOf(context).toString();
final longNumberFormat = NumberFormat.currency(locale: myLocale, symbol: mySymbol, decimalDigits: 2);
print(longNumberFormat.format(1234));

And the result of this is:

for the locale 'en_US': $1,234.00

for the locale 'es' or 'es_AR': 1.234,00 $

In the first case (en_US) it is correct, but for the last case (es_AR) which is Argentina Spanish (my country) it is wrong, we don't use the symbol at the end, we use it in front like the US, but the dots/commas are correct.

This is a mistake of the library? Is there a work around for this?

Thanks

Mark Watney
  • 307
  • 5
  • 13

2 Answers2

3

As above, es_AR isn't in the data. You can't modify that file, as it's generated from CLDR data, and would get overwritten. But you can modify it at runtime to add a missing entry or modify an existing one. For example, here I've created an entry where I've taken the "es" entry and moved the currency symbol (\u00a4) to the beginning.

import 'package:intl/intl.dart';
import 'package:intl/number_symbols.dart';
import 'package:intl/number_symbols_data.dart';

main() {
  var argentina = NumberSymbols(
      NAME: "es_AR",
      DECIMAL_SEP: ',',
      GROUP_SEP: '.',
      PERCENT: '%',
      ZERO_DIGIT: '0',
      PLUS_SIGN: '+',
      MINUS_SIGN: '-',
      EXP_SYMBOL: 'E',
      PERMILL: '\u2030',
      INFINITY: '\u221E',
      NAN: 'NaN',
      DECIMAL_PATTERN: '#,##0.###',
      SCIENTIFIC_PATTERN: '#E0',
      PERCENT_PATTERN: '#,##0\u00A0%',
      CURRENCY_PATTERN: '\u00A4#,##0.00\u00A0',
      DEF_CURRENCY_CODE: r'$');

  numberFormatSymbols['es_AR'] = argentina;
  var f = NumberFormat.currency(locale: 'es_AR');
  print(f.format(1234));

}
Alan Knight
  • 2,759
  • 1
  • 15
  • 13
1

Seems like es_AR hasn't been added yet so it falls back to something else, perhaps es?. Perhaps you can contribute to the package and add it yourself? I guess this is where it should go https://github.com/dart-lang/intl/blob/master/lib/number_symbols_data.dart.

Edit: As pointed out, that file is generated from CLDR so the dart file shouldn't be changed. Perhaps you can submit an issue to the github page or go for the solution suggested by Alan Knight.

A.Fagrell
  • 1,052
  • 8
  • 21