# Why does Julia say 1/26=0.038461538461538464

**URL:** <https://discourse.julialang.org/t/why-does-julia-say-1-26-0-038461538461538464/102995>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [August 20, 2023, 3:48am UTC](https://discourse.julialang.org/t/why-does-julia-say-1-26-0-038461538461538464/102995 "2023-08-20T03:48:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![a-boy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/a-boy/32/52360_2.png) [@a-boy](https://discourse.julialang.org/u/a-boy)\
**Post date:** [August 20, 2023, 3:48am UTC](https://discourse.julialang.org/t/why-does-julia-say-1-26-0-038461538461538464/102995/1 "2023-08-20T03:48:21Z")

</div>

julia\> BigFloat(1/26)  
0.0384615384615384636735058165868395008146762847900390625

julia\> 1/26  
0.038461538461538464

In fact, 1/26=0.0384615[384615]… 384615 as a decimal cycle section. So I doubt the value of BigFloat(1/26) and 1/26 giving by Julia are not correct. What happened？

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [August 20, 2023, 3:51am UTC](https://discourse.julialang.org/t/why-does-julia-say-1-26-0-038461538461538464/102995/2 "2023-08-20T03:51:57Z")

</div>

What’s the problem/question here? Floating point numbers have limited precisions, they can’t losslessly represent all real numbers

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [August 20, 2023, 4:03am UTC](https://discourse.julialang.org/t/why-does-julia-say-1-26-0-038461538461538464/102995/3 "2023-08-20T04:03:27Z")

</div>

> [@PSA: floating-point arithmetic](https://discourse.julialang.org/t/psa-floating-point-arithmetic/8678):
>
> Sometimes people are surprised by the results of floating-point calculations such as julia\> 5/6 0.8333333333333334 # shouldn't the last digit be 3? julia\> 2.6 - 0.7 - 1.9 2.220446049250313e-16 # shouldn't the answer be 0? These are not bugs in Julia. They’re consequences of the IEEE-standard 64-bit binary representation of floating-point numbers that is burned into computer hardware, which Julia and many other languages use by default. Brief explanation You can t…

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [August 20, 2023, 4:06am UTC](https://discourse.julialang.org/t/why-does-julia-say-1-26-0-038461538461538464/102995/4 "2023-08-20T04:06:20Z")

</div>

> [@a-boy](#):
>
> julia\> BigFloat(1/26)

```julia
julia> BigFloat(1)/BigFloat(26)
0.03846153846153846153846153846153846153846153846153846153846153846153846153846162

```

The code `BigFloat(1/26)` first computes 1/26 which becomes a Float64 and then converts that to a BigFloat.

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [August 20, 2023, 4:20am UTC](https://discourse.julialang.org/t/why-does-julia-say-1-26-0-038461538461538464/102995/7 "2023-08-20T04:20:04Z")

</div>

Yes or `BigFloat(1//26)` which takes the exact rational `1//26` and converts it to BigFloat.

> [@a-boy](#):
>
> why the output of 1/26 is 0.038461538461538464, not 0.038461538461538462?

I’m going to assume there are no bugs in the Intel/AMD chips etc, so the number it gives must be the closest 64 bit binary floating point number to the correct value. Let’s see:

```julia
julia> eps(1/26)
6.938893903907228e-18

julia> 1/26 + eps(1/26)
0.03846153846153847

julia> 1/26 - eps(1/26)
0.03846153846153846

```

It looks like it was rounded right I guess.

---

<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:** [August 20, 2023, 1:05pm UTC](https://discourse.julialang.org/t/why-does-julia-say-1-26-0-038461538461538464/102995/8 "2023-08-20T13:05:44Z")

</div>

> [@dlakelan](#):
>
> ```julia
> julia> 1/26 + eps(1/26)
> 0.03846153846153847
> 
> julia> 1/26 - eps(1/26)
> 0.03846153846153846
> 
> ```

You usually want to use `prevfloat`/`nextfloat`, `eps` is the maximum of the distances to the two adjacent floating point numbers, which is not always the same between the two of them (otherwise it’d be the same for _all_ numbers)
