RepoPilot

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

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

Question

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

RepoPilot

Yes, you can! Use the binary option set to true when calling prettyBytes().

Here's how it works:

import prettyBytes from 'pretty-bytes';

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

When binary is false (the default), you get decimal SI Prefix units like kB, MB, GB, etc. [BYTE_UNITS in index.js:L1-L9]. When you set binary: true, you get Binary Prefix units like KiB, MiB, GiB, etc. instead [BIBYTE_UNITS in index.js:L11-L19].

According to the documentation [readme.md:L79-L82], this option is useful for presenting memory amounts, though it should not be used for presenting file sizes.

FOLLOW_UPS:

  • How do I display bits instead of bytes?
  • What happens with the locale option?
  • Can I control decimal places in the output?

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.