title: Formatting a currency depending upon the currency code selected regardless of device's locale (Swift)
body: <p>I am trying to format currencies depending on the currency selected by the user. If no currency is selected, then device's current locale is used for formatting. however, I am having issues:</p>
  <p>I am using a number formatter to format the double to currency string.</p>
  <pre><code>let formatter = NumberFormatter()
      formatter.numberStyle = .currency
      formatter.currencySymbol = &quot;&quot;
          
      if currencyCode != nil {
          formatter.currencyCode = currencyCode
      }
          
      let amount = Double(amt/100) + Double(amt%100)/100
      return formatter.string(from: NSNumber(value: amount))
  }
  </code></pre>
  <p>The currencyCode is basically the currency the user has selected. However, if say the user selects EURO, the formatting is pretty much the same as for USD, meaning that it is not respecting the currency selected. I know that we cannot possibly create a Locale out of currencyCode since EUR is used in 26 different countries so it's impossible to derive the correct locale.</p>
  <p>Also since I am using a format which basically fills the decimals position, then ONES, Tenths and so on and some currencies don't support decimal positions for example, PKR (Pakistani Ruppee) so how can I cater for that?</p>
  <p><strong>So my question is how can I format a currency correctly regardless of which device locale is selected.
  If my device locale is say USD and I create a EUR list, I would like all payments inside the list to be in EUR format.
  So if in USD a price is $3,403.23 in EUR it should be € 3 403,23.</strong></p>
  <p>Any advice on how I should go about formatting? Thanks!</p>