0

I have mobile bank app. When user type amount, then convert string to double i have problem user typed amount example "8.7" is 8.699999999999999 and when i send request it sending 8.699999999999999 what can i do, to fix it?

I have tried this post:

swift: issue in converting string to double

var amount = "8.7" var amountDouble = Double(amount)!

var amount = "8.7" . //"8.7" var amountDouble = Double(amount)! //8.699999999999999

1 Answers1

1

This imprecision is exactly why Double isn't an appropriate datatype for financial domains. Use Decimal instead, which is have perfect precision within its legal range.

Alexander
  • 59,041
  • 12
  • 98
  • 151