Skip to content
Snippets Groups Projects
Unverified Commit ba25b11c authored by Tom Robinson's avatar Tom Robinson Committed by GitHub
Browse files

Merge pull request #9513 from shaohua/patch-1

Round the number correctly before sending it off
parents 35bfa422 1023a95a
Branches
Tags
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.
Please register or to comment