Repository navigation
Conversation
Formatting 9.996 with %.2f printed 1.000. A carry from 999 to 1000 was counted as a discarded place, so the point moved left by one. Fixes ericlagergren#178 Fixes ericlagergren#198
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.
Summary
fmt.Sprintf("%.2f", d)for9.996208266660printed1.000instead of10.00. The same path printed0.099999999999999999999999999999998with%.6fas0.010000instead of0.100000.When rounding carries from
999to1000,roundStringkeeps the extra digit and leaves the caller to place the point. The formatter treated that digit as a discarded place, so the point moved one position left and the displayed value was ten times too small. Values below 1 then dropped that carry digit as well.9.94with%.1fis still9.9.1.25with%.1fis still1.2.2.5with%.0fis still2.Test plan
TestDecimal_Formatfails on the old formatter (1.000vs10.00) and passes with this changego test -count=1 -run 'TestDecimal_Format|TestRoundString|TestBig_Format|TestDecomposer'Fixes #178
Fixes #198