SK2's Product has localizedPriceString, but some users (including me) might need to calculate other prices, like "cost per month" for their UI. This is my app for example:

I used to calculate that like this on version 3.x:
private extension Purchases.Package {
var pricePerMonth: NSDecimalNumber {
let periodsPerMonth: Int = {
switch self.product.subscriptionPeriod?.unit {
case .day: return 30
case .week: return 4
case .month: return 1
case .year: return 12
default: return 1
}
}() / (self.product.subscriptionPeriod?.numberOfUnits ?? 1)
return self.product.price.dividing(by: NSDecimalNumber(value: periodsPerMonth))
}
var localizedPricePerMonth: String {
let formatter = NumberFormatter()
formatter.numberStyle = .currency
formatter.locale = self.product.priceLocale
return formatter.string(from: self.pricePerMonth)! + " " + Strings.Dates.Unit.perMonth
}
}
Luckily the locale is part of the jsonRepresentation of an SK2 Product.
SK2's
ProducthaslocalizedPriceString, but some users (including me) might need to calculate other prices, like "cost per month" for their UI. This is my app for example:I used to calculate that like this on version 3.x:
Luckily the locale is part of the
jsonRepresentationof an SK2Product.