RepoPilot

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

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

Question

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

RepoPilot

Yes, you can use the binary option to get binary units (KiB, MiB, etc.) instead of decimal units (kB, MB, etc.).

Set binary: true in the options object:

import prettyBytes from 'pretty-bytes';

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

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

  • It uses base-2 calculations (powers of 1024) instead of base-10 (powers of 1000)
  • The unit names change to binary versions: B, KiB, MiB, GiB, TiB, etc. (shown in [index.js:L15-L22])

According to the README, this is useful for presenting memory amounts, though it should not be used for file sizes.

FOLLOW_UPS:

  • What's the difference between binary and decimal units?
  • How do I format numbers as bits instead of bytes?
  • Can I combine binary option 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.