Skip to content

printf minimum width issue with %g #16977

Closed

Description

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

bugIndicates an unexpected problem or unintended behaviordisplay and printingAesthetics and correctness of printed representations of objects.help wantedIndicates that a maintainer wants help on an issue or pull request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions