Skip to content

Size formatters print "1000 KB", "1024 KB" and "100.0 KB" at unit boundaries #141

Done

Description

@nixfred

What happens

bytes() in web/src/ui.tsx (line 23) picks the unit first and rounds afterwards, so a value just below a unit boundary rounds up to the boundary and keeps the smaller unit:

while (n >= base && i < units.length - 1) { n /= base; i++ }
return `${n.toFixed(n >= 100 || i === 0 ? 0 : digits)} ${units[i]}`
bytes(999999)            -> "1000 KB"   (should be "1.0 MB")
bytes(99950)             -> "100.0 KB"  (the 100+ branch prints no decimals, so it should be "100 KB")
bytes(999999999999999)   -> "1000 TB"   (should be "1.0 PB")
bytes(1048575, 1, 1024)  -> "1024 KB"   (should be "1.0 MB")
bytes(1023.6, 1, 1024)   -> "1024 B"

The other copies of this helper have the same flaw with base 1024: bytes in web/src/backups.tsx (line 48) and bytes in web/src/unraid.tsx (line 17) both print "1024 KB" for 1048575 (the loop stops at n >= 1024, but toFixed(0) then rounds 1023.999 up). web/src/swarm/gauges.ts (line 29) is a verbatim copy of the ui.tsx version.

Users see these in file sizes, disk and memory gauges, backup sizes and the Unraid import list, for example a 999,999 byte file shown as "1000 KB".

How to reproduce

I copied the function into a scratch .mjs file and ran it:

bytes(999999)            // "1000 KB"
bytes(99950)             // "100.0 KB"
bytes(1048575, 1, 1024)  // "1024 KB"

Expected: "1.0 MB", "100 KB", "1.0 MB".

Suggested fix

Round first, then check whether the rounded value reached the base and move to the next unit (or decide the number of digits from the rounded value). Better, keep one shared helper instead of four copies.

Environment

Omarchy Server main (0786ba9, 0.9.50), Node 26.

Activity

  1. calledtoconstruct commented on Nov 20, 2026

    @calledtoconstruct
    Collaborator

    This stays the single issue for the size formatter printing "1000 KB", "1024 KB", and "100.0 KB". The report already covers the copies in web/src/ui.tsx, web/src/backups.tsx, web/src/unraid.tsx, and web/src/swarm/gauges.ts.

    #436 stays separate. That one is the Machines screen labelling a binary size "GB".

    Posted by Grok 4.7 via Grok Build.

  2. calledtoconstruct commented on Nov 22, 2026

    @calledtoconstruct
    Collaborator

    Working to resolve this.

    No open pull request references this issue, and no one has commented that they are working on it.

    #400, #396, #152, #150, #403, #784, #656, #241, #533, #194, and #213 share the desktop with this and will land in one pull request.

    🤖 Generated with Grok 4.7

  3. calledtoconstruct commented on Dec 5, 2026

    @calledtoconstruct
    Collaborator

    Thank you @nixfred. Machine gauges and the Unraid import list now use the same size formatter as the rest of the app, so a size on a unit boundary reads 1.0 MB. Merged in #1273.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions