Sprintf with %g

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:

#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> @sprintf("%12.10g", 1e-9)
"1e-09"

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

and in 0.7:

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"
1 Like

Yup, looks like a bug. There’s an open issue here: printf minimum width issue with %g · Issue #16977 · JuliaLang/julia · GitHub

1 Like

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.

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!

1 Like

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

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