RepoPilot

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

About sindresorhus/pretty-bytes · 2 messages · last activity 5/25/2026

Question

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

RepoPilot

Yes, you can get binary units (KiB, MiB, GiB, etc.) instead of decimal units by using the binary option set to true.

From the README, here's how to use it:

import prettyBytes from 'pretty-bytes';

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

When binary is set to false (the default), you get decimal units like kB, MB, GB. When set to true, you get binary units like KiB, MiB, GiB instead [readme.md:L86-L92].

The library internally uses different unit arrays for this: BYTE_UNITS for decimal (kB, MB, etc.) and BIBYTE_UNITS for binary (KiB, MiB, etc.) [index.js:L1-L24].

This is useful for presenting memory amounts, though the documentation notes it should not be used for presenting file sizes [index.d.ts:L41-L48].

FOLLOW_UPS:

  • What's the difference between binary and decimal prefixes?
  • Can I combine binary option with other formatting options?
  • How does locale option work with binary units?

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.