RepoPilot

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

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

Question

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

RepoPilot

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

Here's how it works:

import prettyBytes from 'pretty-bytes';

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

When you enable the binary option, the library uses binary prefixes instead of SI prefixes. This means:

  • Without binary (default): Uses decimal units like kB, MB, GB (base-10, where 1 kB = 1000 bytes)
  • With binary: true: Uses binary units like KiB, MiB, GiB (base-2, where 1 KiB = 1024 bytes)

The available binary units are defined in [index.js:L12-L20] as BIBYTE_UNITS and BIBIT_UNITS (if using bits as well).

According to the documentation, this is particularly useful for presenting memory amounts, though it should not be used for presenting file sizes [index.d.ts:L41-L49].

FOLLOW_UPS:

  • What does the bits option do in prettyBytes?
  • How do I format with a specific number of decimal places?
  • Can I use non-breaking spaces 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.