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/8/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:
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.
Example usage:
import prettyBytes from 'pretty-bytes';
prettyBytes(1024, {binary: true});
//=> '1 KiB'
By default, binary is false, so pretty-bytes uses base-10 decimal units (kB, MB, etc.). When you set binary: true, it switches to base-2 binary units (KiB, MiB, etc.) instead.
FOLLOW_UPS:
- What's the difference between binary and decimal units?
- Can I combine binary with other options like signed?
- Does binary affect how the number is formatted?
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.