# Sprintf with %g

**URL:** <https://discourse.julialang.org/t/sprintf-with-g/10857>\
**Category:** Internals & Design\
**Tags:** formatting\
**Created:** [May 12, 2018, 2:06pm UTC](https://discourse.julialang.org/t/sprintf-with-g/10857 "2018-05-12T14:06:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [May 12, 2018, 2:06pm UTC](https://discourse.julialang.org/t/sprintf-with-g/10857/1 "2018-05-12T14:06:20Z")

</div>

apologies for disturbing. it is so close to 1.0 that I wanted to make sure that the following julia behavior is what you wanted and not a bug:

```julia
#include <stdio.h>

int main() {
  printf("'%12.10g'\n", 1e-2);
  printf("'%12.10g'\n", 1e-9);
}

' 0.01'
' 1e-09'

```

Note the string width in 0.6.2:

```julia
julia> @sprintf("%12.10g", 1e-9)
"1e-09"

julia> @sprintf("%12.10g", 1e-2)
" 0.01"

```

and in 0.7:

```julia
julia> using Printf

julia> @sprintf("%12.10g", 1e-2)
WARNING: Base.@sprintf is deprecated: it has been moved to the standard library package `Printf`.
Add `using Printf` to your imports.
 in module Main
" 0.01"

julia> @sprintf("%12.10g", 1e-9)
WARNING: Base.@sprintf is deprecated: it has been moved to the standard library package `Printf`.
Add `using Printf` to your imports.
 in module Main
"1e-09"

```

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [May 12, 2018, 5:05pm UTC](https://discourse.julialang.org/t/sprintf-with-g/10857/2 "2018-05-12T17:05:42Z")

</div>

Yup, looks like a bug. There’s an open issue here: [printf minimum width issue with %g · Issue #16977 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/16977)

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [May 12, 2018, 8:24pm UTC](https://discourse.julialang.org/t/sprintf-with-g/10857/3 "2018-05-12T20:24:09Z")

</div>

I see. I wonder why this has not been fixed in two years. is it difficult or considered relatively unimportant? in any case, with 1.0 impending, this would be a nice fix to throw in.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [May 12, 2018, 8:53pm UTC](https://discourse.julialang.org/t/sprintf-with-g/10857/4 "2018-05-12T20:53:55Z")

</div>

I think it’s nothing more or less than the fact that no one has yet stepped up to do it. It could be you!

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [May 12, 2018, 10:45pm UTC](https://discourse.julialang.org/t/sprintf-with-g/10857/5 "2018-05-12T22:45:52Z")

</div>

trust me, you wouldn’t want me to do this! 😉

I am thinking of julia as a professional development by julia computing. I signed up for their support contract to make a better contribution than an attempt to tinker with their code base.

regards,

/iaw
