Fix formatting of decimal powers below 1 million#2431
Merged
coolreader18 merged 1 commit intoRustPython:masterfrom Feb 1, 2021
merkrafter:fix/decimal-powers-formatting
Merged
Fix formatting of decimal powers below 1 million#2431coolreader18 merged 1 commit intoRustPython:masterfrom merkrafter:fix/decimal-powers-formatting
coolreader18 merged 1 commit intoRustPython:masterfrom
merkrafter:fix/decimal-powers-formatting
Conversation
The previous implementation truncated even 10.0 to 1, because it cut away any combination of trailing 0's and .'s.
6 tasks
coolreader18
approved these changes
Feb 1, 2021
Member
coolreader18
left a comment
There was a problem hiding this comment.
Nice catch, thank you for contributing!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The previous implementation truncated all decimal powers of 10.0 below 1 million (by default) to 1, because it cut away any
combination of trailing 0's and .'s.
(Powers of 10.0 beginning with 1000000.0 are formatted to an exponential format and thus not affected by the bug.)
My fix now checks whether the number string to truncate represents a floating point value at all and if that is the case, truncation stops at the decimal point.
(The check whether there is a decimal point in the string to truncate is necessary as
format!("{:.*}", precision, magnitude)withprecision==0does return strings without a decimal point; truncating those is fatal)