Compact float printing in the REPL

You can redefine the show method for float. @which show(stdout, 2/3) shows you where it is, @less prints it. This modification might work:

julia> function Base.show(io::IO, x::Union{Float64,Float32})
                 Base.Grisu._show(io, round(x, sigdigits=3), Base.Grisu.SHORTEST, 0, get(io, :typeinfo, Any) !== typeof(x), false)
         end                                                                                                                                                            
                                                                                                                                                                        
julia> 2/3                                                                                                                                                              
0.667                                                                                                                                                                   

julia> rand(10)                                                                                                                                                         
10-element Array{Float64,1}:                                                                                                                                            
 0.684                                                                                                                                                                  
 0.594                                                                                                                                                                  
 0.0643
 0.695                                                                                                                                                                  
 0.524                                                                                                                                                                  
 0.884                                                                                                                                                                  
 0.541                                                                                                                                                                  
 0.49                                                                                                                                                                   
 0.175                                                                                                                                                                  
 0.561                                                                                                                                                                  

(Note, there is a certain danger in redefining Base-methods! But should be ok for show)

4 Likes