Skip to content

Commit

Permalink
Merge pull request #276 from afterpay/markmroz/fix-locale-formatting
Browse files Browse the repository at this point in the history
Use CheckoutV3 region for currency formatting
  • Loading branch information
mmroz authored Aug 22, 2024
2 parents d79ccce + 003b40c commit 6f70db2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 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 = {
var formatter = NumberFormatter()
private var formatter: NumberFormatter {
let 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 6f70db2

Please sign in to comment.