# Why 1-0.4 = 0.6 vs 1 - 1.4 = -0.399999999999

**URL:** <https://discourse.julialang.org/t/why-1-0-4-0-6-vs-1-1-4-0-399999999999/129148>\
**Category:** General Usage\
**Created:** [May 19, 2025, 2:36pm UTC](https://discourse.julialang.org/t/why-1-0-4-0-6-vs-1-1-4-0-399999999999/129148 "2025-05-19T14:36:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![BMval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmval/32/7647_2.png) [@BMval](https://discourse.julialang.org/u/BMval)\
**Post date:** [May 19, 2025, 2:36pm UTC](https://discourse.julialang.org/t/why-1-0-4-0-6-vs-1-1-4-0-399999999999/129148/1 "2025-05-19T14:36:22Z")

</div>

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

Julia ver 1.11.5

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [May 19, 2025, 2:37pm UTC](https://discourse.julialang.org/t/why-1-0-4-0-6-vs-1-1-4-0-399999999999/129148/2 "2025-05-19T14:37:09Z")

</div>

> **[Floating Point Math](https://0.30000000000000004.com/)**

Also [PSA: floating-point arithmetic](https://discourse.julialang.org/t/psa-floating-point-arithmetic/8678)

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [May 19, 2025, 2:48pm UTC](https://discourse.julialang.org/t/why-1-0-4-0-6-vs-1-1-4-0-399999999999/129148/3 "2025-05-19T14:48:39Z")

</div>

Mose’s answer is what you need to read, but also just to directly answer your question

> [@BMval](#):
>
> 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

```julia
julia> (0.2 - 0.6) ≈ (0.1 - 0.5)
true

```

(that’s `\approx<TAB>`)

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [May 19, 2025, 3:14pm UTC](https://discourse.julialang.org/t/why-1-0-4-0-6-vs-1-1-4-0-399999999999/129148/4 "2025-05-19T15:14:11Z")

</div>

Oh, that question wasn’t there when I replied 😅

---

<div class="post-metadata">

**Author:** ![mikmoore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikmoore/32/31109_2.png) [@mikmoore](https://discourse.julialang.org/u/mikmoore)\
**Post date:** [May 19, 2025, 4:22pm UTC](https://discourse.julialang.org/t/why-1-0-4-0-6-vs-1-1-4-0-399999999999/129148/5 "2025-05-19T16:22:56Z")

</div>

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-repl
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 `BigInt` `Rational`s.)

```julia-repl
julia> 1 - 14//10
-2//5

julia> Float64(1 - 14//10) # great! except...
-0.4

julia> big(Float64(1 - 14//10)) # -0.4 simply doesn't exist in binary floating point
-0.40000000000000002220446049250313080847263336181640625

```
