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/20/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 [readme.md:L76-L87], here's how:
import prettyBytes from 'pretty-bytes';
prettyBytes(1000, {binary: true});
//=> '1000 B'
prettyBytes(1024, {binary: true});
//=> '1 KiB'
The binary option is documented in [index.d.ts:L30-L46] as:
Format the number using the Binary Prefix instead of the SI Prefix. This can be useful for presenting memory amounts. However, this should not be used for presenting file sizes.
By default, binary is false, which means the library uses base-10 (decimal) units like kB, MB, GB. Setting binary: true switches to base-2 (binary) units like KiB, MiB, GiB.
FOLLOW_UPS:
- What's the difference between SI and binary prefixes?
- Can I combine binary option with other options?
- How are values rounded when using binary units?
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.