Skip to content

Commit

Permalink
Fix currency formatting using locale instead of region
Browse files Browse the repository at this point in the history
  • Loading branch information
mmroz committed Aug 21, 2024
1 parent d79ccce commit 6d47b78
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Sources/Afterpay/AfterpayV3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -347,18 +347,19 @@ public struct CheckoutV3Configuration {
return currencyCode
}

private static var formatter: NumberFormatter = {
private var formatter: NumberFormatter {
var formatter = NumberFormatter()
formatter.numberStyle = .decimal
// ISO 4217 specifies 2 decimal points
formatter.maximumFractionDigits = 2
formatter.roundingMode = .halfEven // Banker's rounding
formatter.groupingSeparator = ""
formatter.locale = locale
return formatter
}()
}

func formatted(currency: Decimal) -> String {
return Self.formatter.string(from: currency as NSDecimalNumber)!
return formatter.string(from: currency as NSDecimalNumber)!
}
}
}

0 comments on commit 6d47b78

Please sign in to comment.