fix(tui): roll the compact form over to M at the rounding boundary (#55871)

Co-authored-by: argszero <argszero@users.noreply.github.com>
Co-authored-by: Tarquinen <78942835+Tarquinen@users.noreply.github.com>
This commit is contained in:
argszero
2026-10-16 07:34:22 +08:00
committed by GitHub
Unverified
parent 13263f30ed
commit 2e7ac8c8ea
2 changed files with 8 additions and 1 deletions
+2 -1
View File
@@ -17,7 +17,8 @@ export function datetime(input: number): string {
}
export function number(num: number): string {
if (num >= 1000000) {
// 999950+ would round to "1000.0K"
if (num >= 999950) {
return (num / 1000000).toFixed(1) + "M"
} else if (num >= 1000) {
return (num / 1000).toFixed(1) + "K"
+6
View File
@@ -12,3 +12,9 @@ test("takes whole graphemes within terminal width", () => {
expect(Locale.takeWidth("ab界cd", 4)).toBe("ab界")
expect(Locale.graphemes("a👨‍👩‍👧‍👦b")).toEqual(["a", "👨‍👩‍👧‍👦", "b"])
})
test("rolls the compact form over at the rounding boundary", () => {
expect(Locale.number(999949)).toBe("999.9K")
expect(Locale.number(999950)).toBe("1.0M")
expect(Locale.number(1000000)).toBe("1.0M")
})