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

Add support for '%' type to output floating point values as a percentage. #1060

Closed
wants to merge 4 commits into from

Conversation

gawain-bolton
Copy link
Contributor

This helps with compatibility with Python's format strings.

percentage.

This helps with compatibility with Python's format strings.
@vitaut
Copy link
Contributor

vitaut commented Mar 3, 2019

Thanks for the PR, but please fix the CI build, apply clang-format to your changes and add a unit test.

* Added percentage sign if needed when dumping nan and infinity.
* Added unit tests.
* Used clang-format for changed source files.
@gawain-bolton
Copy link
Contributor Author

Thanks for the PR, but please fix the CI build, apply clang-format to your changes and add a unit test.

I have applied clang-format and added unit tests.
The CI builds also now pass.

if (internal::fputil::isinfinity(value)) {
write_inf_or_nan(handler.upper ? "INF" : "inf");
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks unrelated. Please revert.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I've reverted this changes.


if (handler.as_percentage) {
buffer.push_back('%');
--exp; // Adjust decimal place position.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be -= 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The decimal place position is shifted by one place because only one character, the percent sign, is added.

@vitaut
Copy link
Contributor

vitaut commented Mar 6, 2019

Merged in 79b79f3, thanks!

@vitaut vitaut closed this Mar 6, 2019
@vitaut
Copy link
Contributor

vitaut commented Aug 11, 2019

@gawain-bolton, could you please review the updated CONTIBUTING document, particularly the part about licensing, and let me know if you agree with it being applied to your contributions to {fmt}? The library is likely to be relicensed (#1073) so I'm collecting approval from all earlier contributors. Thanks!

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

Successfully merging this pull request may close these issues.

2 participants