gpo
gpo

Reputation: 3689

In-app price format for Google Analytics

My app contains in-app products that can be purchased. I use the billing API to retrieve the list of products that can be purchased and their prices. The retrieved price is a formatted String containing both the currency and price, for instance "$2.50".

Now I use as well Google Analytics API to track purchases. For sending the price, this API takes a long parameter in micros. So I should send (2.50*1000000).

Is there an API to convert the first price (retrieved from Billing API) to the second one (to send to Analytics API)?

Of course I could do a simple String parsing conversion myself, but I'm afraid of unexpected cases if I do so. For instance, in some locales, the price would contain "," instead of ".".

Edit

A natural solutions would be to use NumberFormat to convert from "$2.50" to 2.50.

Double price = NumberFormat.getCurrencyInstance().parse(priceStr).doubleValue();

However, the price string format retrieved from Google Play is apparently in the locale of the country where the phone is located, but the NumberFormat would use the locale of the phone which is not necessarily the same...

Upvotes: 8

Views: 1188

Answers (1)

Markus Hi
Markus Hi

Reputation: 1729

Although it's not officially documented the Billing API already provides the necessary data in the getSkuDetails() response.

Besides the price field you also retrieve the following:

price_currency_code The ISO currency code

price_amount_micros The product price in micros (Note: net price)

Upvotes: 1

Related Questions