Repository navigation
fix(utils): use the right unit in the auto number formatter - #3360
Open
SwastikTripathi wants to merge 1 commit into
Open
SwastikTripathi wants to merge 1 commit into
SwastikTripathi wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
👀 PR includes
🐛 Bugfix
📝 Description
auto(exported from@antv/s2) puts every number one unit too high. Its doc comment says numbers under 10,000 get thousands separators (3,459) and larger ones get a unit (3.2万,3.4亿), but:The
whileloop incrementslooponce more on the iteration that stops, sotexts[loop - 1]is always the next unit, and once all units are used it reads past the end oftexts. The existing test case pinned this output (expect(auto(3459)).toStrictEqual('3,459 万')).The loop now counts only the units it divides by. After
toFixed, a value that rounds up to the next power (9999.999 to 10000) moves to the next unit, so it becomes1 万instead of10,000 万. Negative numbers are handled as before.🖼️ Screenshot
auto(34590000)=3,459 亿3,459 万The output only changes where it had the wrong unit. Nothing inside S2 calls
auto.🔗 Related issue link
None.
🔍 Self-Check before the merge
Updated the cases in
__tests__/unit/utils/formatter-spec.tsto the documented output and added1e9,3.2 万,3.4 亿and a rounding carry case. The new expectations fail before the change (Expected: "0",Received: "0 万") and pass after, run withjest --runner=jest-runner --env=node(the electron runner doesn't start on this machine). eslint and prettier are clean.