Printf打印
该 Printf打印 模块提供类似于C标准库的格式化输出函数 printf打印. 它允许格式化打印到输出流或字符串。
# *`Printf的。@printf`*-马科罗_
@printf([io::IO], "%Fmt", args...)
印刷业 阿格斯 使用C printf打印 样式格式规范字符串。 任选地,一个 伊俄 可以作为重定向输出的第一个参数传递。
*例子*
julia> @printf "Hello %s" "world"
Hello world
julia> @printf "Scientific notation %e" 1.234
Scientific notation 1.234000e+00
julia> @printf "Scientific notation three digits %.3e" 1.23456
Scientific notation three digits 1.235e+00
julia> @printf "Decimal two digits %.2f" 1.23456
Decimal two digits 1.23
julia> @printf "Padded to length 5 %5i" 123
Padded to length 5 123
julia> @printf "Padded with zeros to length 6 %06i" 123
Padded with zeros to length 6 000123
julia> @printf "Use shorter of decimal or scientific %g %g" 1.23 12300000.0
Use shorter of decimal or scientific 1.23 1.23e+07
julia> @printf "Use dynamic width and precision %*.*f" 10 2 0.12345
Use dynamic width and precision 0.12
有关格式的系统规范,请参阅https://en.cppreference.com/w/c/io/fprintf[这里]。 @sprintf得到结果为 字符串 而不是被打印出来。
*注意事项*
资讯 和 南 被一致地打印为 资讯 和 南 旗帜 %a, %A, %e, %E, %f, %F, %g,而 %G. 此外,如果浮点数同样接近两个可能的输出字符串的数值,则选择远离零的输出字符串。
*例子*
julia> @printf("%f %F %f %F", Inf, Inf, NaN, NaN)
Inf Inf NaN NaN
julia> @printf "%.0f %.1f %f" 0.5 0.025 -0.0078125
0 0.0 -0.007812
|
兼容性
朱莉娅1.8从朱莉娅1.8开始, |
|
兼容性
Julia1.10动态宽度说明符,如 |
# *`Printf的。格式`*-类型
Printf.Format(format_str)
创建可用于格式化值的c printf兼容format对象。
输入 格式_str 可以包括任何有效的格式说明符字符和修饰符。
A 格式 对象可以传递给 Printf。格式(f::Format,args...) 生成格式化字符串,或 Printf。格式(io::IO,f::Format,args...) 要将格式化的字符串直接打印到 伊俄.
为方便起见, Printf。格式"。.." 字符串宏形式可用于构建一个 Printf的。格式 对象在宏观-扩展-时间。
|
兼容性
朱莉娅1.6 |