Skip to content
Snippets Groups Projects
Commit 1023a95a authored by shaohua's avatar shaohua Committed by shaohua
Browse files

Round the number correctly before sending it off

This fix https://github.com/metabase/metabase/issues/9072

The bug is inside the lib:
https://github.com/HubSpot/humanize/blob/master/src/humanize.js#L86
```
const number = parseInt(input, 10);
```

Fix #9072. Round up number when compact is true

Minor copy
parent 35bfa422
No related branches found
No related tags found
No related merge requests found
......@@ -261,7 +261,7 @@ function formatNumberCompact(value: number) {
} else {
// 1 => 1
// 1000 => 1K
return Humanize.compactInteger(value, 1);
return Humanize.compactInteger(Math.round(value), 1);
}
}
......
......@@ -35,6 +35,12 @@ describe("formatting", () => {
expect(formatNumber(0.01, { compact: true })).toEqual("~ 0");
expect(formatNumber(-0.01, { compact: true })).toEqual("~ 0");
});
it("should round up and down", () => {
expect(formatNumber(1.01, { compact: true })).toEqual("1");
expect(formatNumber(-1.01, { compact: true })).toEqual("-1");
expect(formatNumber(1.9, { compact: true })).toEqual("2");
expect(formatNumber(-1.9, { compact: true })).toEqual("-2");
});
it("should format large numbers with metric units", () => {
expect(formatNumber(1, { compact: true })).toEqual("1");
expect(formatNumber(1000, { compact: true })).toEqual("1.0k");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment