RepoPilot

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

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

Question

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

RepoPilot

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

According to the README, here's how:

import prettyBytes from 'pretty-bytes';

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

The binary option formats the number using the Binary Prefix instead of the default SI Prefix. This is useful for presenting memory amounts, though it should not be used for presenting file sizes [readme.md:L80-L84].

When binary: true is set, the library uses the BIBYTE_UNITS array (B, KiB, MiB, GiB, TiB, PiB, EiB, ZiB, YiB) instead of the default BYTE_UNITS array (B, kB, MB, GB, TB, PB, EB, ZB, YB) [index.js:L14-L22].

FOLLOW_UPS:

  • What's the difference between KiB and kB?
  • Can I use binary units with bits instead?
  • How do I combine binary option with other 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.