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 8/1/2026
Yes, pretty-bytes respects the user's locale for number formatting through the locale option.
The locale option accepts multiple formats [index.d.ts:L10-L18]:
false(default): Output won't be localizedtrue: Localize using the system/browser localestring: A specific BCP 47 language tag (e.g.,'de','en')string[]: A list of BCP 47 language tags to try in order
The implementation uses the toLocaleString function [index.js:L55-L65], which delegates to JavaScript's native Number#toLocaleString() method. This applies locale-specific formatting to both the number itself and the decimal separator.
For example [test.js:L71-L110]:
- German locale (
'de'):prettyBytes(1001, {locale: 'de'})returns'1 kB'with a comma decimal separator - English locale (
'en'):prettyBytes(1001, {locale: 'en'})returns'1 kB'with a period decimal separator
Important caveat [readme.md:L122-L124]: Only the number and decimal separator are localized. The unit titles (like 'kB', 'MB') are not localized and remain in English.
FOLLOW_UPS:
- How does the fixedWidth option work for alignment?
- What's the difference between binary and SI prefix formatting?
- Can you use both locale and minimumFractionDigits together?
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.