I am trying to pass a format string as a function argument in the following code -
using Printf
fmt = "%.0e"
function latex_exp_note(flt,fmt)
s = @sprintf(fmt,flt)
b,e = split(s,"e")
e = replace(e,"+"=>"")
e = replace(e,"0"=>"")
s = raw"$"*b*raw"\times 10^{"*e*raw"}$"
s = replace(s,"{}"=>"{0}")
return latexstring(s)
end
display(latex_exp_note(2.5,fmt))
when I run the code I get this error -
LoadError: ArgumentError: First argument to @sprintf
must be a format string.
how do it define fmt
to be a format string that can be passed into a function?