Support new API

This commit is contained in:
Ali
2021-03-26 18:33:46 +04:00
parent 3009fe790f
commit de34ab5efa
14 changed files with 1020 additions and 195 deletions

View File

@@ -46,6 +46,28 @@ private func loadCurrencyFormatterEntries() -> [String: CurrencyFormatterEntry]
private let currencyFormatterEntries = loadCurrencyFormatterEntries()
public func fractionalToCurrencyAmount(value: Double, currency: String) -> Int64? {
guard let entry = currencyFormatterEntries[currency] ?? currencyFormatterEntries["USD"] else {
return nil
}
var factor: Double = 1.0
for _ in 0 ..< entry.decimalDigits {
factor *= 10.0
}
return Int64(value * factor)
}
public func currencyToFractionalAmount(value: Int64, currency: String) -> Double? {
guard let entry = currencyFormatterEntries[currency] ?? currencyFormatterEntries["USD"] else {
return nil
}
var factor: Double = 1.0
for _ in 0 ..< entry.decimalDigits {
factor *= 10.0
}
return Double(value) / factor
}
public func formatCurrencyAmount(_ amount: Int64, currency: String) -> String {
if let entry = currencyFormatterEntries[currency] ?? currencyFormatterEntries["USD"] {
var result = ""