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
Are you looking for something like 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
.
For the whole REPL session, you can redefine the show function. Next REPL will be back to normal.
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
2 Likes
thanks @Seif_Shebl