0

Consider the code below:

    var finalValue:Double!

    let aValue:Double = 1.6
    let bValue:Double = 64.0

    finalValue = bValue / (aValue*aValue)

    if finalValue == 25.0 {
        print("value \(finalValue) is equal to 25")
    } else {
        print("value \(finalValue) is not equal to 25")
    }

I expect the result is "value 25.0 is equal to 25" But Xcode prints "value 25.0 is not equal to 25" which is wrong!!!!!

How can I solve the problem?

I'm using Xcode Version 7.0.1 (7A1001)

oOEric
  • 1,069
  • 1
  • 10
  • 25
  • 4
    Welcome to floating point arithmetic. Suggest you do some reading about that topic. – elixenide Oct 22 '15 at 04:36
  • Thanks. Finally I use this workaround: `let finalValueString: String = String(format: "%.1f", finalValue) |||| finalValue = Double(finalValueString)` – oOEric Oct 22 '15 at 06:22

0 Answers0