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 6/29/2026
Question
RepoPilot
Yes, pretty-bytes respects the user's locale for number formatting through the locale option.
The locale option supports multiple modes [index.js:L55-L65]:
false(default): Output won't be localized—numbers use standard formattingtrue: Uses the system/browser locale automaticallystring: Accepts a BCP 47 language tag (e.g.,'de','en')string[]: Accepts a list of language tags with fallback support
The implementation uses the toLocaleString function [index.js:L55-L65], which calls Number#toLocaleString() with the specified locale. For example:
prettyBytes(1337, {locale: 'de'})→'1,34 kB'(German decimal separator)prettyBytes(1337, {locale: 'en'})→'1.34 kB'(English decimal separator)prettyBytes(1e30, {locale: 'en'})→'1,000,000 YB'(English thousand separators)prettyBytes(1e30, {locale: 'de'})→'1.000.000 YB'(German thousand separators)
The test file [test.js:L71-L110] confirms these locale-aware behaviors across different scenarios including negative numbers and very large values.
FOLLOW_UPS:
- What other formatting options does pretty-bytes support?
- How does the binary prefix option work?
- Can you customize decimal places in output?
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.