Repository navigation
Commit e893c61
committed
fix: JS formatBytes unit index off-by-one for realtime updates
The JS formatBytes used floor(log1000(b)) directly as the units index,
but this returns a value 1 too high. For 642MB (642000000 bytes):
log1000 gives ~2.94 → floor 2 → units[2]='GB' (wrong, should be MB).
Root cause: Go formatBytes counts how many times b/1000 is still ≥ 1000
(loop condition n >= unit), which produces exp where divisor=1000^(exp+1).
But JS formula floor(log1000(b)) counts how many times b ≥ 1000^n
without the extra division check, making it off by 1.
Fix: separate exp (power of 1000) from i (units index), where i = exp-1
and divisor = 1000^exp. This mirrors the Go logic exactly.1 parent 95fa0ae commit e893c61
1 file changed
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
| 9 | + | |
9 | 10 | | |
10 | | - | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
0 commit comments