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

Guidance for %g equivalent #9

Open
jason-s opened this issue Aug 26, 2024 · 1 comment
Open

Guidance for %g equivalent #9

jason-s opened this issue Aug 26, 2024 · 1 comment
Labels
feature request Request for a new feature

Comments

@jason-s
Copy link

jason-s commented Aug 26, 2024

C/C++, Python, and Java all support the %g formatting specifier, which effectively selects between %e and %f as appropriate. I was surprised to learn that Rust does not.

If this library is trying to stay close to Rust std::fmt, I wouldn't change the implementation, but please provide some guidance in the documentation for those of us who are used to specifying %g. (either we can't do it, or we should consider a workaround = ???)

@PgBiel PgBiel added the feature request Request for a new feature label Sep 2, 2024
@PgBiel
Copy link
Owner

PgBiel commented Sep 2, 2024

If I understood correctly, you can work around it by using oxifmt's strfmt to format your number with both scientific and decimal formats, retaining only the formatted string with the shortest length. (This can be encapsulated in a function for ease of use.) You'd then substitute the result into your larger string with another call to oxifmt's strfmt.

We could consider having this built into oxifmt at some point once I think of a proper design for "extensions".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for a new feature
Projects
None yet
Development

No branches or pull requests

3 participants
@jason-s @PgBiel and others