How to show annual subscription price per month?

  • 20 August 2022
  • 5 replies

Badge +3

Sorry if it was asked before, I searched but couldn’t find anything :(

What is the best way to calculate the price for annual subscription per month/week? I want to show user, how much he/she will pay for an annual subscription each month or week.

I see that there is a pricePerMonth property on StoreProduct and it calculates correctly, but it shows only the numbers, without currency symbols such as $.

Thank you!

5 replies

Userlevel 4
Badge +7

You will want to use the number formatting methods of the respective platform you are using, e.g., NSNumberFormatter on iOS or NumberFormat on Android. (If you are using a hybrid toolkit such as React Native or Flutter, they have methods / packages for this as well).

Badge +1

Is it possible to get Locale for StoreProduct? (on iOS)

Userlevel 4
Badge +7

You should be able to get the NumberFormatter from the StoreProduct, and you can get the locale from the NumberFormatter.

Isn’t this such a often used feature? I think it’s kind of cumbersome, that there is a localizedPriceString but for this I need to use a custom formatter.

Userlevel 4
Badge +8

@michst if you need to use a custom formatter, my advice would be to either: 

  • Get the locale from the formatter like Jens mentioned, and then create a formatter with the locale like we do here, or
  • Start with your formatter, and just set the locale and currency, again like in the example code. 

So in general the options are to either use the pricePerMonth with the priceFormatter provided in StoreProduct, or use the pricePerMonth with your own formatter, using the locale in the formatter within StoreProduct.