Can I get binary (KiB, MiB) units instead of decimal? How?
Can I get binary (KiB, MiB) units instead of decimal? How?
About sindresorhus/pretty-bytes · 2 messages · last activity 7/27/2026
Yes, you can get binary units (KiB, MiB, etc.) instead of decimal units by using the binary option set to true.
According to the README, the binary option formats the number using the Binary Prefix instead of the SI Prefix, which is useful for presenting memory amounts [readme.md:L80-L95].
Here's how to use it:
import prettyBytes from 'pretty-bytes';
prettyBytes(1000, {binary: true});
//=> '1000 B'
prettyBytes(1024, {binary: true});
//=> '1 KiB'
The key difference is that binary mode uses base-2 units (KiB, MiB, GiB, etc.) rather than the default base-10 units (kB, MB, GB, etc.). The available binary units are defined in the source as BIBYTE_UNITS [index.js:L13-L22], which include: B, KiB, MiB, GiB, TiB, PiB, EiB, ZiB, and YiB.
FOLLOW_UPS:
- What's the difference between binary and decimal units?
- Can I use binary units with bits instead of bytes?
- How do I format numbers with specific decimal places?
Want to ask your own question?
Open chat for sindresorhus/pretty-bytesPublic 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.