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

Formatting for fixed-width with _two_ decimal places is resulting in _three_ #1072

Closed
tonyelewis opened this issue Mar 8, 2019 · 7 comments

Comments

@tonyelewis
Copy link
Contributor

I expect the expression:

fmt::format( "{:.2f}", 0.01 )

…to result in "0.01"s but it's returning "0.010"s.

Thanks for all your hard work on this excellent library and on standardising it.

@tonyelewis
Copy link
Contributor Author

In another example, I expect the expression:

fmt::format( "{:7.3f}", 1E-35F )

…to result in " 0.000"s (two spaces) but it's returning "1.00e-35"s. Am I misunderstanding f?

@tonyelewis
Copy link
Contributor Author

In case I am misunderstanding…

The above two results are consistent with the number between the . and the f specifying the fixed-width's number of significant figures rather than decimal places. But the docs say it indicates:

how many digits should be displayed after the decimal point

…and the expression:

::fmt::format( "{:.2f}", 0.01F )

…returns "0.01"s.

@vitaut
Copy link
Contributor

vitaut commented Mar 9, 2019

Thanks for reporting. The new floating-point formatting algorithm is being integrated into the master branch thus some temporary formatting weirdness. This will be addressed soon and in the meantime I recommend using one of the stable releases.

@vitaut
Copy link
Contributor

vitaut commented Mar 9, 2019

I've also disabled the new algorithm for fixed formatting for now: d560dda, so your examples should produce expected results.

@tonyelewis
Copy link
Contributor Author

Ah, OK. Thanks for the quick response and for fixing master. I've reverted to 5.3.0 and my tests now pass cleanly. I'm happy for this issue to be closed.

Again thanks for all you work on the library and on standardisation.

@vitaut
Copy link
Contributor

vitaut commented Mar 10, 2019

Fixed in 3466d9c and 49d244c.

@vitaut vitaut closed this as completed Mar 10, 2019
@tonyelewis
Copy link
Contributor Author

Great stuff. Thanks for addressing this so quickly.

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

No branches or pull requests

2 participants