Is there a way to force the decimal notation for floats for printing or writing in a file?
@sprintf
can do that:
julia> @sprintf("%.3f", Float64(π))
"3.142"
julia> @sprintf("%.8f", Float64(π))
"3.14159265"
julia> @sprintf("%.8f", 3e8)
"300000000.00000000"
Or, if you want to print to a stream directly, then @printf
:
julia> @printf(STDOUT, "%f", π)
3.141593
I often use @printf
to do such printing.