How to print a number to X digits?

,

You can set it for a whole REPL session instead of for every instance. For example, the following uses 4-digit MATLAB-like formatting:

julia> using Printf

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

julia> 1.0
1.0000

julia> 2/3
0.6667

julia> rand(5)
5-element Array{Float64,1}:
 0.4112
 0.4889
 0.1706
 0.4589
 0.7526
9 Likes