Printf

Printf.@printf — Macro

1. @printf([io::IO], "%Fmt", args...)

Print args using C printf style format specification string. Optionally, an IO may be passed as the first argument to redirect output.

Examples

1. julia> @printf "Hello %s" "world"
2. Hello world

4. julia> @printf "Scientific notation %e" 1.234
5. Scientific notation 1.234000e+00

7. julia> @printf "Scientific notation three digits %.3e" 1.23456
8. Scientific notation three digits 1.235e+00

10. julia> @printf "Decimal two digits %.2f" 1.23456
11. Decimal two digits 1.23

13. julia> @printf "Padded to length 5 %5i" 123
14. Padded to length 5   123

16. julia> @printf "Padded with zeros to length 6 %06i" 123
17. Padded with zeros to length 6 000123

19. julia> @printf "Use shorter of decimal or scientific %g %g" 1.23 12300000.0
20. Use shorter of decimal or scientific 1.23 1.23e+07

For a systematic specification of the format, see here. See also: @sprintf.

Caveats

Inf and NaN are printed consistently as Inf and NaN for flags %a, %A, %e, %E, %f, %F, %g, and %G. Furthermore, if a floating point number is equally close to the numeric values of two possible output strings, the output string further away from zero is chosen.

Examples

1. julia> @printf("%f %F %f %F", Inf, Inf, NaN, NaN)
2. Inf Inf NaN NaN

4. julia> @printf "%.0f %.1f %f" 0.5 0.025 -0.0078125
5. 0 0.0 -0.007812

source

Printf.@sprintf — Macro

1. @sprintf("%Fmt", args...)

Return @printf formatted output as string.

Examples

1. julia> @sprintf "this is a %s %15.1f" "test" 34.567
2. "this is a test            34.6"

source