# Floating point addition in Julia

**URL:** <https://discourse.julialang.org/t/floating-point-addition-in-julia/72341>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 1, 2021, 5:07am UTC](https://discourse.julialang.org/t/floating-point-addition-in-julia/72341 "2021-12-01T05:07:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![n90](https://avatars.discourse-cdn.com/v4/letter/n/439d5e/32.png) [@n90](https://discourse.julialang.org/u/n90)\
**Post date:** [December 1, 2021, 5:07am UTC](https://discourse.julialang.org/t/floating-point-addition-in-julia/72341/1 "2021-12-01T05:07:00Z")

</div>

I am a bit confused about the floating value addition in Julia. When I try to add two float values in Julia am getting a non rounded value with more precision.

julia\> 106.8 + 1.085  
107.88499999999999

I want to know if there is a way I can round the result as follows.

julia\> 106.8 + 1.085  
107.885

I have tested the round(value, digit=N) method to get the above result.

Why is the result not rounded by default and Is there any other way to get the rounded result besides round() function.

---

<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:** [December 1, 2021, 5:15am UTC](https://discourse.julialang.org/t/floating-point-addition-in-julia/72341/2 "2021-12-01T05:15:38Z")

</div>

Welcome! It’s an artifact of IEEE float point arithmetic, see more: [https://0.30000000000000004.com/](https://0.30000000000000004.com/)

---

<div class="post-metadata">

**Author:** ![n90](https://avatars.discourse-cdn.com/v4/letter/n/439d5e/32.png) [@n90](https://discourse.julialang.org/u/n90)\
**Post date:** [December 1, 2021, 5:29am UTC](https://discourse.julialang.org/t/floating-point-addition-in-julia/72341/3 "2021-12-01T05:29:05Z")

</div>

> [@jling](#):
>
> It’s an artifact of IEEE float point arithmetic

Hey thank you for the answer. I understood why it is happening. But is there a way I can round the result other than using a function?

---

<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:** [December 1, 2021, 5:31am UTC](https://discourse.julialang.org/t/floating-point-addition-in-julia/72341/4 "2021-12-01T05:31:07Z")

</div>

if you’re asking if there’s a way to set global/per environment precision, the answer is no.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [December 1, 2021, 5:32am UTC](https://discourse.julialang.org/t/floating-point-addition-in-julia/72341/5 "2021-12-01T05:32:02Z")

</div>

Use `Fraction`s or `Decimals.jl`

---

<div class="post-metadata">

**Author:** ![adolgert](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adolgert/32/20286_2.png) [@adolgert](https://discourse.julialang.org/u/adolgert)\
**Post date:** [December 2, 2021, 12:16am UTC](https://discourse.julialang.org/t/floating-point-addition-in-julia/72341/6 "2021-12-02T00:16:58Z")

</div>

Continuing from @Oscar_Smith, …or use [GitHub - JuliaMath/FixedPointNumbers.jl: fixed point types for julia](https://github.com/JuliaMath/FixedPointNumbers.jl) or rational numbers (`3 // 7`). These are all good options, under the right circumstances.

Hey, maybe this post helps: [PSA: floating-point arithmetic](https://discourse.julialang.org/t/psa-floating-point-arithmetic/8678).

---

<div class="post-metadata">

**Author:** ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Post date:** [December 2, 2021, 1:54am UTC](https://discourse.julialang.org/t/floating-point-addition-in-julia/72341/7 "2021-12-02T01:54:33Z")

</div>

You can control the number of digits printed in the REPL, e.g., without loosing precision like this (it will affect printing of all subsequent floats):

```julia
julia> using Printf

julia> Base.show(io::IO, f::Float64) = @printf(io, "%.3f", f)

julia> 106.8 + 1.085
107.885

```
