fix: display sub-one values with two decimal places (#25)

This commit is contained in:
2026-03-08 14:11:53 -07:00
committed by Naomi Carrigan
parent d1d1f70c75
commit b82a2d3da7
2 changed files with 9 additions and 3 deletions
+3 -1
View File
@@ -73,7 +73,9 @@ const formatSuffix = (value: number): string => {
return `${(value / threshold).toFixed(2)}${suffix}`;
}
}
return value.toFixed(1);
return value < 1
? value.toFixed(2)
: value.toFixed(1);
};
/**
+6 -2
View File
@@ -28,8 +28,12 @@ describe("formatNumber", () => {
expect(formatNumber(-1000)).toBe("-1.00K");
});
it("should format zero as '0.0'", () => {
expect(formatNumber(0)).toBe("0.0");
it("should format zero as '0.00'", () => {
expect(formatNumber(0)).toBe("0.00");
});
it("should format small decimal values with two decimal places", () => {
expect(formatNumber(0.01)).toBe("0.01");
});
});