Does this respect the user's locale for number formatting?
Does this respect the user's locale for number formatting?
About sindresorhus/pretty-bytes · 2 messages · last activity 7/6/2026
Yes, the library does respect the user's locale for number formatting through the locale option.
The locale parameter supports three modes [readme.md]:
false(default): Output won't be localizedtrue: Localizes using the system/browser localestringorstring[]: Uses a specific BCP 47 language tag (e.g.,'de','en')
The actual localization is handled by the toLocaleString function [index.js:L55-L65], which calls JavaScript's native Number.prototype.toLocaleString(). For example:
prettyBytes(1337, {locale: 'de'});
//=> '1,34 kB'
This German locale example shows the decimal separator changing from . to ,.
Important caveat: The README explicitly notes that "Only the number and decimal separator are localized. The unit title is not and will not be localized." So while 1,34 uses German formatting, the unit kB remains unchanged.
The locale options are built in buildLocaleOptions [index.js:L110-L123], which passes minimumFractionDigits and maximumFractionDigits settings to toLocaleString if specified.
FOLLOW_UPS:
- How does minimumFractionDigits affect output formatting?
- What happens when locale is set to true?
- Can you pass multiple locales as fallbacks?
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.