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!
How to show annual subscription price per month?
![Why Not Both? Badge](https://uploads-us-west-2.insided.com/revenuecat-en/attachment/ccbc4ad2-bff5-4fe9-b65f-83bbced7a8ac_thumb.png)
I would like access to this priceFormatter in Dart as well. The Dart SDK only seems to provide the currency code (eg. “USD”). The NumberFormat class in Dart does not accept currency codes, only locale. In order format a calculated price in Dart one must translate the currency code to locale, or use an alternative formatter that accepts currency code.
![Strength In Numbers Badge](https://uploads-us-west-2.insided.com/revenuecat-en/attachment/ad9785ad-84a4-4bde-98db-d0de530785fc_thumb.png)
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).
We’re using React Native, but would love to be able to use the exact same price formatter that you’re using in order to make sure it’s as expected. The alternative would be to use something like Intl but as someone mentioned:
...it is not a good idea to read locale from the device or in any other way.
So ideally, I would want a formatter available as part of `react-native-purchases` or to have the user locale available from the package, such as on the customer object.
![Shipped It Badge](https://uploads-us-west-2.insided.com/revenuecat-en/attachment/00177be5-17f2-4400-bea7-87c75adea50f_thumb.png)
Is it possible to get Locale for StoreProduct? (on iOS)
you can get the Locale from storeProduct by calling “storeProduct.priceFormatter.locale”
And it is not a good idea to read locale from the device or in any other way. My project is written in Objective-C and the following method would be helpful to get the pricePerMonth value with the storeProduct’s currency for annual package.
-(NSString *)getFormattedPriceValue:(RCPackage *)thePackage
{
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[numberFormatter setLocale:thePackage.storeProduct.priceFormatter.locale];
NSString *formattedMonthlyPrice = [numberFormatter stringFromNumber:thePackage.storeProduct.pricePerMonth];
return formattedMonthlyPrice;
}
![Strength In Numbers Badge](https://uploads-us-west-2.insided.com/revenuecat-en/attachment/ad9785ad-84a4-4bde-98db-d0de530785fc_thumb.png)
Hi there, just to show some code related to what
let formattedPrice: String
if package.packageType == .annual {
if
let pricePerMonth = package.storeProduct.pricePerMonth,
let priceFormatter = package.storeProduct.priceFormatter,
let localizedPricePerMonth = priceFormatter.string(from: pricePerMonth)
{
formattedPrice = "\(package.localizedPriceString) (\(localizedPricePerMonth)/month)"
} else {
formattedPrice = "\(package.localizedPriceString)"
}
} else {
formattedPrice = "\(package.localizedPriceString)/month"
}
- 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.
![Shipped It Badge](https://uploads-us-west-2.insided.com/revenuecat-en/attachment/00177be5-17f2-4400-bea7-87c75adea50f_thumb.png)
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.
You should be able to get the NumberFormatter from the StoreProduct, and you can get the locale from the NumberFormatter.
![Strength In Numbers Badge](https://uploads-us-west-2.insided.com/revenuecat-en/attachment/ad9785ad-84a4-4bde-98db-d0de530785fc_thumb.png)
Is it possible to get Locale for StoreProduct? (on iOS)
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).
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.