Browse the docs

formatSize

Writes a number of bytes as text, as Finder does.

Details #

formatSize(bytes, style?) writes bytes as Finder does: 1500000 is 1.5 MB, with powers of 1000. Give the style "binary" (or "KiB") for powers of 1024, which is how memory and some tools count. Text such as "1.2 GB" is accepted as the size too.

Parameters #

Takes 1 to 2 arguments. {{ formatSize(text, b?) }}

Examples #

formatSize(1500000)
→ 1.5 MB
formatSize(1048576, "binary")
→ 1 MB

Gotchas #

  • The unit names and number format follow the Mac's language.

  • A negative size fails.