why 1-0.4 = 0.6 vs 1 - 1.4 = -0.399999999999
and 0.1 - 0.5 = -0.4 vs 0.2 - 0.6 = -0.3999999
How to make the calculation consistent? What the best way to deal with that to be able to compare (0.2 - 0.6) == (0.1 - 0.5) to get true, not false as it is right now
To build on previous answers: checking for precise equality in floating point math should be used in only specific situations and with an understanding of roundoff as you see it here. The issue is that the decimal system used by humans is not perfectly matchable by the base-2 floating point system most commonly used by computers. In particular, most numbers with a nice base-10 fractional part do not have a nice base-2 fractional so the result is rounded. You can use big (which uses more but ultimately still a finite number of base-2 bits) to get a little more info about the issue
julia> big(1.0) # this is exactly representable
1.0
julia> big(1.4) # closest available Float64 to 1.400000...
1.399999999999999911182158029987476766109466552734375
julia> big(1.0) - big(1.4)
-0.399999999999999911182158029987476766109466552734375
julia> Float64(big(1.0) - big(1.4)) # round the result to the closest Float64
-0.3999999999999999
Exact float arithmetic is not necessary in many situations. If you really need perfectly accurate base-10 arithmetic, I would suggest you try another approach such as Rational (although it is much slower and may overflow unless you use BigIntRationals.)