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.
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.
Try this:
using Printf
format_float(x) = @sprintf("%.4f", x)
function print_formatted(data)
if isa(data, AbstractArray)
for row in eachrow(data)
println(join([format_float(x) for x in row], "\t"))
end
else
println(format_float(data))
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With