Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get currency symbol from Play Billing Library

I use Play Billing Library and I have two subscriptions for one and three months. For a 3 month subscription, I want to display the price for 1 month. For example, a 1 month subscription is $1,50 and a 3 month subscription is $3 ($1 for a 1 month). But I have some problems with currencies.

This is a code:

long priceAmountMicros = skuDetails.getPriceAmountMicros(); //3000000
String priceCurrency = skuDetails.getPriceCurrencyCode(); //USD

float priceFloat = (float)priceAmountMicros / 3 / 1000000; //1
String price = new DecimalFormat("#0.00").format(priceFloat);

Currency currency = Currency.getInstance(priceCurrency);
String symbolCurrency = currency.getSymbol();//$

textView.setText(price + " " + symbolCurrency); //1.00 $ or 70.00 руб

The code almost is working. USD converted to $. EUR converted to £ and others. There are some problems with some currencies, for example, the Russian currency does not work. RUB converted to руб, but I expect

There is a standard method for getting the price:

String price = skuDetails.getPrice();//3 $ or 210 ₽

Am I doing something wrong? Could you help me please?

like image 904
TimWeb Avatar asked Nov 06 '22 06:11

TimWeb


1 Answers

You can use Currency class from java.util package

Currency.getInstance(sku.priceCurrencyCode).symbol

will give you the symbol for currency code

like image 95
ikbal Avatar answered Nov 15 '22 04:11

ikbal