Skip to content

Fix formatting of decimal powers below 1 million#2431

Merged
coolreader18 merged 1 commit intoRustPython:masterfrom
merkrafter:fix/decimal-powers-formatting
Feb 1, 2021
Merged

Fix formatting of decimal powers below 1 million#2431
coolreader18 merged 1 commit intoRustPython:masterfrom
merkrafter:fix/decimal-powers-formatting

Conversation

@merkrafter
Copy link
Contributor

@merkrafter merkrafter commented Feb 1, 2021

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) with precision==0 does return strings without a decimal point; truncating those is fatal)

The previous implementation truncated even 10.0 to 1, because it cut away any
combination of trailing 0's and .'s.
Copy link
Member

@coolreader18 coolreader18 left a comment

Choose a reason for hiding this comment

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

Nice catch, thank you for contributing!

@coolreader18 coolreader18 merged commit 39ff807 into RustPython:master Feb 1, 2021
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