1 file changed, +3, -2
68f66b8Pick the size unit after rounding, so no size shows as 1000 kb
author
mogi <git@paramogi.world> on 21-11-2026 02:47 UTC
committer
mogi <git@paramogi.world> on 21-11-2026 02:47 UTC
parent0dc027c
+3, -2
      @@ -202,13 +202,14 @@ fn format_bytes(bytes: usize) -> String {
202202     if bytes < 1000 {
203203         return format!("{bytes} b");
204204     }
   205+    let round = |value: f64| (value * 10.0 + 0.5).floor() / 10.0;
205206     let mut value = bytes as f64;
206207     let mut unit = 0;
207   -    while value >= 1000.0 && unit + 1 < BYTE_UNITS.len() {
   208+    while round(value) >= 999.5 && unit + 1 < BYTE_UNITS.len() {
208209         value /= 1000.0;
209210         unit += 1;
210211     }
211   -    let value = (value * 10.0 + 0.5).floor() / 10.0;
   212+    let value = round(value);
212213     if value < 10.0 {
213214         format!("{value:.1} {}", BYTE_UNITS[unit])
214215     } else {