Sprintf with %g


#1

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"

#2

Yup, looks like a bug. There’s an open issue here: https://github.com/JuliaLang/julia/issues/16977


#3

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.


#4

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!


#5

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