0

I try to convert a String decimal like "1.10" to Double object but when I use

    Double("1.10") result is wrong 1.1000000000000001 

but if I use

    Double("1.02") result is ok : 1.02

Did i miss something ?

I use the simulator iPhone XS in Swift 5.0 and Xcode 10.1

Djamal
  • 1
  • Have a look at https://stackoverflow.com/questions/588004/why-do-inaccuracies-occur-in-floating-point-math-operations – Martin R Apr 26 '19 at 21:06
  • 2
    What you are missing is that `Double` is a *binary* floating point number, and cannot represent all numbers exactly. – Martin R Apr 26 '19 at 21:06

0 Answers0