Dart:获取指定语言环境的货币代码

时间:2019-04-23 10:48:51

标签: dart formatting currency

特定的Dart问题。给定语言环境(即'en_US''es_ES',...),如何获取关联的货币符号?

您知道Java中是否有类似于Currency的库? https://docs.oracle.com/javase/8/docs/api/java/util/Currency.html

1 个答案:

答案 0 :(得分:1)

您可以使用intl软件包(https://pub.dartlang.org/packages/intl

import 'package:intl/intl.dart';

main() {
  var formatEnUs = NumberFormat.simpleCurrency(locale: 'en_US');
  print(formatEnUs.currencySymbol); // $
  print(formatEnUs.currencyName); // USD

  var formatEs = NumberFormat.simpleCurrency(locale: 'es_ES');
  print(formatEs.currencySymbol); // €
  print(formatEs.currencyName); // EUR
}