# Passing a format string as a function argument

**URL:** <https://discourse.julialang.org/t/passing-a-format-string-as-a-function-argument/116929>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 11, 2024, 10:32pm UTC](https://discourse.julialang.org/t/passing-a-format-string-as-a-function-argument/116929 "2024-07-11T22:32:34Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![bertschi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bertschi/32/33462_2.png) [@bertschi](https://discourse.julialang.org/u/bertschi)\
**Post date:** [July 11, 2024, 10:54pm UTC](https://discourse.julialang.org/t/passing-a-format-string-as-a-function-argument/116929/2 "2024-07-11T22:54:36Z")

</div>

Short answer, you can’t pass it as an argument to the `@sprintf` macro.  
Instead use the function the macro call expands to:

```julia
s = Printf.format(fmt, fld)

```

and also the format string is not a string, but needs to be preprocessed via

```julia
fmt = Printf.format"%.0e"

```

See this [thread](https://discourse.julialang.org/t/printf-with-variable-format-string/3805) for the discussion of basically the same problem.

---

_[View the full topic](https://discourse.julialang.org/t/passing-a-format-string-as-a-function-argument/116929)._
