How to print a number to X digits?

,
julia> using Printf

julia> a = 1;

julia> @printf("%.3f\n", a)
1.000

There’s also @sprintf to get a string value, see Printf · The Julia Language for details.

3 Likes