-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Conversation
percentage. This helps with compatibility with Python's format strings.
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.
I have applied clang-format and added unit tests. |
include/fmt/format.h
Outdated
if (internal::fputil::isinfinity(value)) { | ||
write_inf_or_nan(handler.upper ? "INF" : "inf"); | ||
return; | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Merged in 79b79f3, thanks! |
@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! |
This helps with compatibility with Python's format strings.