title: Casting currency values from JSON to NSDecimalNumber
body: <p>I get the following JSON response from an API.</p>
  
  <pre><code>{
    "status": "success",
    "data": [
      {
        "actual_price": 30,
        "offered_deal_price": 16,
        "pending_balance": 12.8
      }
    ]
  }
  </code></pre>
  
  <p>All those values are prices. Which means they can be round values or floating values.</p>
  
  <p>I <a href="https://stackoverflow.com/q/28421176/1077789">read</a> that you should use <code>NSDecimalNumber</code> type for currency values. I'm having trouble converting these JSON values.</p>
  
  <p>Doing this,</p>
  
  <pre><code>json["pending_balance"] as! NSDecimalNumber
  </code></pre>
  
  <p>failed with the following error.</p>
  
  <p><strong>Could not cast value of type '__NSCFNumber' (0x10423ccf0) to 'NSDecimalNumber' (0x1046cf1f0)</strong></p>
  
  <p>Trying to cast it to <code>NSDecimal</code> resulted in this </p>
  
  <p><strong>Could not cast value of type '__NSCFNumber' (0x7f9102f79f68) to 'C.NSDecimal' (0x10f23d6e0)</strong>.</p>
  
  <p>I <em>can</em> however, cast it to Swift types like <code>Float</code> or <code>Double</code> without an issue.</p>
  
  <p>Anyone got an idea what's the problem with <code>NSDecimalNumber</code>? Or is it safe to go ahead with <code>Float</code> or <code>Double</code>? If so which one is the best for currency values?</p>
  
  <p>Thank you.</p>