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 6/29/2026
Yes, you can get binary units (KiB, MiB, etc.) by using the binary option set to true.
According to the README, here's how:
import prettyBytes from 'pretty-bytes';
prettyBytes(1024, {binary: true});
//=> '1 KiB'
When binary is set to true, the library uses binary prefixes (powers of 1024) instead of SI prefixes (powers of 1000). The available binary units are defined in [index.js:L15-L22] as BIBYTE_UNITS: B, KiB, MiB, GiB, TiB, PiB, EiB, ZiB, YiB.
Note that the README explicitly states: "However, this should not be used for presenting file sizes" — binary prefixes are more appropriate for presenting memory amounts [readme.md:L82-L85].
FOLLOW_UPS:
- How do I format bits with binary prefixes?
- What's the difference between KiB and kB?
- Can I combine binary with the signed option?
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.