Double value conversion issue

I am trying to subtract one double value with another but I am getting an invalid result. The result for 4.15 - 0.2 works but fails for 4.14 and 4.13.

Replies

Double represents values in binary floating point system.

So, every programming language may show the same results.

One way would be showing the result with proper rounding.

Another might be using Decimal instead of Double.

But which would be better depends on your use case.

  • Yes you were right. I tried it with VS and it was returning what Xcode did. Thanks for the response :)

Add a Comment

This may help you:

https://developer.apple.com/forums/thread/695376

Add a Comment