# Uniformly set floating point sig digits in a code

**URL:** <https://discourse.julialang.org/t/uniformly-set-floating-point-sig-digits-in-a-code/53482>\
**Category:** New to Julia\
**Created:** [January 17, 2021, 11:59am UTC](https://discourse.julialang.org/t/uniformly-set-floating-point-sig-digits-in-a-code/53482 "2021-01-17T11:59:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![R\_Surya\_Narayan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/r_surya_narayan/32/7867_2.png) [@R\_Surya\_Narayan](https://discourse.julialang.org/u/R_Surya_Narayan)\
**Post date:** [January 17, 2021, 11:59am UTC](https://discourse.julialang.org/t/uniformly-set-floating-point-sig-digits-in-a-code/53482/1 "2021-01-17T11:59:39Z")

</div>

Hello guys, I am using Julia for scientific computation and would like to know if there is a way to set the significant digits of all floating point variables in the code to a specified value. I know I can use `round(var, sigdigits=n)` but it requires me to perform this for _every variable_ in my code. Is there a way to do it in a single shot?  
Thanks

---

<div class="post-metadata">

**Author:** ![roflmaostc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roflmaostc/32/30123_2.png) [@roflmaostc](https://discourse.julialang.org/u/roflmaostc)\
**Post date:** [January 17, 2021, 1:47pm UTC](https://discourse.julialang.org/t/uniformly-set-floating-point-sig-digits-in-a-code/53482/2 "2021-01-17T13:47:31Z")

</div>

Are you looking for something like [FixedPointNumbers.jl](https://github.com/JuliaMath/FixedPointNumbers.jl)?

And are you sure that you want to `round` intermediate results? Depending on the situation, the rounding errors can completely dominate the result.  
If you want to have less memory usage, you might try `Float16` or `Float32`.

---

<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:** [January 17, 2021, 1:50pm UTC](https://discourse.julialang.org/t/uniformly-set-floating-point-sig-digits-in-a-code/53482/3 "2021-01-17T13:50:06Z")

</div>

For the whole REPL session, you can redefine the show function. Next REPL will be back to normal.

```julia
julia> using Printf

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

julia> rand(5,5)
5×5 Matrix{Float64}:
 0.3295 0.7265 0.5993 0.5268 0.8041
 0.8736 0.8861 0.2600 0.9450 0.2365
 0.4777 0.1362 0.2872 0.1366 0.4631
 0.0829 0.5563 0.2298 0.9434 0.2490
 0.4327 0.0836 0.2727 0.8882 0.4711

```

---

<div class="post-metadata">

**Author:** ![R\_Surya\_Narayan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/r_surya_narayan/32/7867_2.png) [@R\_Surya\_Narayan](https://discourse.julialang.org/u/R_Surya_Narayan)\
**Post date:** [January 17, 2021, 1:51pm UTC](https://discourse.julialang.org/t/uniformly-set-floating-point-sig-digits-in-a-code/53482/4 "2021-01-17T13:51:07Z")

</div>

thanks @Seif_Shebl
