Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

printf minimum width issue with %g #16977

Closed
chriscoey opened this issue Jun 17, 2016 · 4 comments
Closed

printf minimum width issue with %g #16977

chriscoey opened this issue Jun 17, 2016 · 4 comments
Assignees
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects. kind:bug Indicates an unexpected problem or unintended behavior status:help wanted Indicates that a maintainer wants help on an issue or pull request

Comments

@chriscoey
Copy link

Is this behavior incorrect in the second case below?

julia> @printf "|%8.2g|" 0.0000312
| 3.1e-05|
julia> @printf "|%8.2g|" 0.00003
| 3e-05|

In the second case, only 6 characters are printed between the bars, yet I specified with %8 that a minimum of 8 chars should be printed.

One option is to pad the extra spaces before 3. Otherwise, print a decimal and zero after 3, which is the same (correct) behavior as:

julia> @printf "|%#8.2g|" 0.00003
| 3.0e-05|

Bumping #10610, Julia might benefit from rethinking print formatting.

@StefanKarpinski StefanKarpinski added this to the 0.5.x milestone Sep 13, 2016
@StefanKarpinski StefanKarpinski self-assigned this Sep 13, 2016
@StefanKarpinski StefanKarpinski added the domain:strings "Strings!" label Sep 14, 2016
@StefanKarpinski StefanKarpinski added status:help wanted Indicates that a maintainer wants help on an issue or pull request and removed status:help wanted Indicates that a maintainer wants help on an issue or pull request labels Oct 27, 2016
@JeffBezanson JeffBezanson added kind:bug Indicates an unexpected problem or unintended behavior domain:display and printing Aesthetics and correctness of printed representations of objects. and removed domain:strings "Strings!" labels May 21, 2018
@JeffBezanson JeffBezanson modified the milestones: 0.5.x, 1.0.x May 21, 2018
@ghost ghost mentioned this issue Jul 9, 2019
@quinnj
Copy link
Member

quinnj commented Aug 12, 2019

Yes, this is fixed in #32859

@TXKurt
Copy link

TXKurt commented Sep 2, 2020

Hello,

I found this thread because I was having a similar problem and it isn't fixed.
The length of the string below should be 14:

julia> import Printf; length(Printf.@sprintf("%14g",-9.4369e-16))
13

It's missing a leading space with all the releases I have: 0.7, 1.0.5, 1.5.1 (Windows).

@quinnj
Copy link
Member

quinnj commented Sep 2, 2020

@TXKurt , to get the fix, you need to checkout the branch of code in #32859, like git checkout origin jq/printf, then run make, then your julia will have the code that contains the fix for this. For example, I just ran your code on that branch and see:

julia> import Printf; length(Printf.@sprintf("%14g",-9.4369e-16))
14

julia> Printf.@sprintf("%14g",-9.4369e-16)
"   -9.4369e-16"

@quinnj
Copy link
Member

quinnj commented Sep 8, 2020

Fixed in #32859

@quinnj quinnj closed this as completed Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects. kind:bug Indicates an unexpected problem or unintended behavior status:help wanted Indicates that a maintainer wants help on an issue or pull request
Projects
None yet
Development

No branches or pull requests

5 participants