Dart:获取给定语言环境的货币代码
Dart: Get the currency code given a locale
具体的 Dart 问题。给定一个语言环境(即 'en_US'
、'es_ES'
、...),我如何获得关联的货币符号?
你知道Java中有没有类似Currency
的库? https://docs.oracle.com/javase/8/docs/api/java/util/Currency.html
您可以使用 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
}
具体的 Dart 问题。给定一个语言环境(即 'en_US'
、'es_ES'
、...),我如何获得关联的货币符号?
你知道Java中有没有类似Currency
的库? https://docs.oracle.com/javase/8/docs/api/java/util/Currency.html
您可以使用 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
}