julia

Round everything to 4 decimal places


Is there global setting to round everything that's printed to the terminal in Julia to 4 decimal places?

Any print - float, arrays, matrices, dataframes, structures - if it has float it should be printed with 4 digits after decimal point, like 2.0000.


Solution

  • You could try by overriding the Base.show() method in julia like so:

    import Printf
    
    function Base.show(io::IO, f::Float64)
        Printf.@printf(io, "%.4f", f)
    end
        
    

    After executing this code, any Float64 value printed to the terminal will be rounded to four decimal places.