mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Fix decimal rounding
This commit is contained in:
parent
a4a358cdaf
commit
53085d396e
@ -13,6 +13,18 @@ private let productIdentifiers = [
|
|||||||
"org.telegram.telegramPremium.threeMonths"
|
"org.telegram.telegramPremium.threeMonths"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
private extension NSDecimalNumber {
|
||||||
|
func round(_ decimals: Int) -> NSDecimalNumber {
|
||||||
|
return self.rounding(accordingToBehavior:
|
||||||
|
NSDecimalNumberHandler(roundingMode: .down,
|
||||||
|
scale: Int16(decimals),
|
||||||
|
raiseOnExactness: false,
|
||||||
|
raiseOnOverflow: false,
|
||||||
|
raiseOnUnderflow: false,
|
||||||
|
raiseOnDivideByZero: false))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public final class InAppPurchaseManager: NSObject {
|
public final class InAppPurchaseManager: NSObject {
|
||||||
public final class Product: Equatable {
|
public final class Product: Equatable {
|
||||||
private lazy var numberFormatter: NumberFormatter = {
|
private lazy var numberFormatter: NumberFormatter = {
|
||||||
@ -47,7 +59,7 @@ public final class InAppPurchaseManager: NSObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func pricePerMonth(_ monthsCount: Int) -> String {
|
public func pricePerMonth(_ monthsCount: Int) -> String {
|
||||||
let price = self.skProduct.price.dividing(by: NSDecimalNumber(value: monthsCount))
|
let price = self.skProduct.price.dividing(by: NSDecimalNumber(value: monthsCount)).round(2)
|
||||||
return self.numberFormatter.string(from: price) ?? ""
|
return self.numberFormatter.string(from: price) ?? ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user