RepoPilot

Can I get binary (KiB, MiB) units instead of decimal? How?

About sindresorhus/pretty-bytes · 2 messages · last activity 6/15/2026

Question

Can I get binary (KiB, MiB) units instead of decimal? How?

RepoPilot

Yes, you can use binary units by setting the binary option to true.

The library defines separate unit arrays for binary formatting. When binary: true is set, the function uses BIBYTE_UNITS (for bytes) or BIBIT_UNITS (for bits) instead of the default decimal units [index.js:L1-L34].

Here's how to use it:

import prettyBytes from 'pretty-bytes';

prettyBytes(1024, {binary: true});
//=> '1 KiB'

The key difference is:

  • Without binary option (default): Uses SI prefix (base-10) → 1000 bytes = 1 kB
  • With binary: true: Uses binary prefix (base-2) → 1024 bytes = 1 KiB

As shown in the examples, prettyBytes(1000, {binary: true}) returns '1000 B' (still bytes since it's below 1 KiB), while prettyBytes(1024, {binary: true}) returns '1 KiB' [readme.md:L86-L90].

The unit selection logic is in the main function [index.js:L139-L141], where it chooses between BIBYTE_UNITS or BYTE_UNITS based on your binary option setting.

FOLLOW_UPS:

  • What's the difference between KiB and kB?
  • How do I display bits instead of bytes?
  • Can I combine binary with other formatting options?

Want to ask your own question?

Open chat for sindresorhus/pretty-bytes

Public Q&A. Generated by RepoPilot from the actual source of sindresorhus/pretty-bytes. AI answers can be incomplete or stale — verify before relying on them.