Search code examples
iosswiftlocalecurrencynumber-formatting

Swift Currency formatter for locale fr_CA


I am formatting my currency using locale fr_CA, I use below code to do

    let formatter = NumberFormatter()
    formatter.locale = Locale(identifier: "fr_CA")
    formatter.numberStyle = .currency
    if let formattedTipAmount = formatter.string(from: 33 as NSNumber) {
        print(formattedTipAmount)
    }

I am getting output as 33,00 $, but my expected output as 33,00 CAD

Do I need to manually replace last symbol($) with (CAD) or any other proper way of doing it. Kindly help me.


Solution

  • Do I need to manually replace last symbol($) with (CAD)…

    Yes, you do.

    let formatter = NumberFormatter()
    formatter.locale = Locale(identifier: "fr_CA")
    formatter.numberStyle = .currency
    formatter.currencySymbol = "CAD"
    if let formattedTipAmount = formatter.string(from: 33) {
        print(formattedTipAmount)
    }