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

Unexpected trailing zeros in to_string(double) #1153

Closed
alabuzhev opened this issue May 10, 2019 · 4 comments
Closed

Unexpected trailing zeros in to_string(double) #1153

alabuzhev opened this issue May 10, 2019 · 4 comments

Comments

@alabuzhev
Copy link
Contributor

std::cout << fmt::to_string(1234.0);

Previously (for years) this was printing "1234".
Now it prints "1234.0" and, of course, breaks someone's workflow.

Probably related to #1129.

@vitaut
Copy link
Contributor

vitaut commented May 10, 2019

Thanks for reporting. The default has changed to the shortest decimal representation to follow the standards proposal, so this is expected. If you want some specific format please use the fmt::format function instead.

@vitaut vitaut closed this as completed May 10, 2019
@alabuzhev
Copy link
Contributor Author

Ok, thanks.
And what the format string should be used then please?
#1129 mentions ":g", but fmt::format("{0:g}", 1234.0) gives "1234.", i.e. with the decimal point character.

@alabuzhev
Copy link
Contributor Author

P.S.
Python: "{0:.16g}".format(1234.0) -> 1234
C: printf("%.16g", 1234.0); -> 1234

@vitaut vitaut reopened this May 10, 2019
@vitaut
Copy link
Contributor

vitaut commented May 10, 2019

g is a correct option and trailing . there is a bug.

alabuzhev added a commit to alabuzhev/fmt that referenced this issue May 10, 2019
alabuzhev added a commit to alabuzhev/fmt that referenced this issue May 10, 2019
@vitaut vitaut closed this as completed May 11, 2019
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