Open junder873 opened 4 months ago
It would probably be better to use StrFormat.jl, which adds formatting (as well as other functionality, both with C style and Python style, provided by Format.jl) to interpolated strings.
julia> using StrFormat
Precompiling StrFormat...
3 dependencies successfully precompiled in 4 seconds. 1 already precompiled.
julia> f"(\{0.2f}(pi))"
"(3.14)"
If I want to create a string from a custom format, it seems like I am supposed to use
cfmt
orformat
, but these do not have complete flexibility.For example, if I want to create a string for $\pi$ surrounded by parentheses (
(3.14)
), how would I do that?printfmtln
will display it:printfmtln("({:0.2f})", π)
, but this returns nothing (so it cannot be used later in the program). I triedcfmt
butcfmt("(%0.2f)", π)
causes an error. It is possible throughformat
by runningformat(-π; parens=true)
but this is not always work if I want something else besides parentheses.With Printf, this is possible:
Printf.format(Printf.Format("(%0.2f)"), π)
will return a string. So cancfmt
be extended to accept similar options?