Dart:获取给定区域设置的货币代码

问题描述 投票:2回答:1

具体的飞镖问题。给定一个区域(即'en_US''es_ES',......),我如何获得相关的货币符号?

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

dart formatting currency
1个回答
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
}
© www.soinside.com 2019 - 2024. All rights reserved.