Is there a way to use @sprintf with “parametric” format string? or it has to be hardcoded?
This is an example:
julia> @sprintf(“test: %s”, “test”)
“test: test”
julia> fmt = “test: %s”; @sprintf(fmt, “test”)
ERROR: LoadError: ArgumentError: @sprintf: first argument must be a format string
julia> import Printf: Format, format
julia> function test(n,x)
f = Format("%10.$(n)f")
format(f,x)
end
test (generic function with 1 method)
julia> test(3,1.0)
" 1.000"
julia> test(5,1.0)
" 1.00000"