title: Swift: Decode imprecise decimal correctly
body: <p>I need to decode (<code>Decodable</code> protocol) an imprecise decimal value correctly, from <a href="https://stackoverflow.com/questions/42781785/how-to-store-1-66-in-nsdecimalnumber">this question</a> I understand how to properly handle the Decimal instantiation, but how can I do this when decoding?</p>
  
  <p>If trying to init any number as a String</p>
  
  <pre><code>if let value = try! container.decode(String.self, forKey: .d) {
      self.taxAmount = Decimal(string: value)
  }
  </code></pre>
  
  <p>I get <code>Fatal Error: "Expected to decode String but found a number instead."</code></p>
  
  <p>And if try to init 130.43 as a Decimal</p>
  
  <pre><code>if let value = try! container.decode(Decimal.self, forKey: .d) {
      //value.description is 130.43000000000002048
      self.d = Decimal(string: value.description)
      //making subtotal to be also 130.43000000000002048 and not 130.43
  }
  </code></pre>
  
  <p>Is there any way to use either of this constructors when decoding?</p>
  
  <ul>
  <li><code>NSDecimalNumber(string: "1.66")</code></li>
  <li><code>NSDecimalNumber(value: 166).dividing(by: 100)</code></li>
  <li><code>Decimal(166)/Decimal(100)</code></li>
  <li><code>Decimal(sign: .plus, exponent: -2, significand: 166)</code></li>
  </ul>
  
  <p>Here is a simplified version of the JSON I receive from the external service:</p>
  
  <pre><code>{
     "priceAfterTax": 150.00,
     "priceBeforeTax": 130.43,
     "tax": 15.00,
     "taxAmount": 19.57
  }
  </code></pre>
  
  <p>Note: I can't change what is being received to be decoded, I'm stuck working with decimal numbers.</p>