获取基于国家的货币符号 [英] Get the currency symbol based on country

查看:165
本文介绍了获取基于国家的货币符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TextView这显示货币。默认情况下我的TextView的文字是: $ 0.00包装 我怎样才能使它所以基于用户选择的 $ 的变化。

I have a TextView which display currencies. By default my textview's text is: $0.00 How can I make it so the $ changes based on user selection.

我有以下的code:

Locale locale=new Locale("en", "US");
Currency currency=Currency.getInstance(locale);
String symbol = currency.getSymbol();
Toast.makeText(getActivity(), symbol, Toast.LENGTH_SHORT).show();

这说明 $ ,但如果我有以下几点:

Which shows $ but if I have the following:

Locale locale=new Locale("en", "AU");
Currency currency=Currency.getInstance(locale);
String symbol = currency.getSymbol();
Toast.makeText(getActivity(), symbol, Toast.LENGTH_SHORT).show();

它显示了 AU $ 而不是 $

如何设置的货币符号,而所有多余的东西?

How can I set the currency symbol without all the extra stuff?

推荐答案

如果你想要的是该格式添加一个数字,你有你可以做

If what you want is to add that format to a number you have you could do

myString = NumberFormat.getCurrencyInstance().format(myNumber);

有关默认 或

myString = NumberFormat.getCurrencyInstance(new Locale("en", "AU")).format(myNumber);

指定

这篇关于获取基于国家的货币符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆