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/15/2026
Yes, pretty-bytes does respect the user's locale for number formatting. The library provides a locale option that controls how numbers are formatted according to different localization standards.
The locale option works in three ways [README]:
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 delegates to JavaScript's native Number.toLocaleString() method. When a locale is specified as a string or array, it's passed directly to this method:
if (typeof locale === 'string' || Array.isArray(locale)) {
result = number.toLocaleString(locale, options);
}
For example, the test suite demonstrates locale-specific formatting [test.js:L71-L110]:
- German (
'de') uses comma as decimal separator and periods for thousands:'1,34 kB'→'1.000.000 YB' - English (
'en') uses period as decimal separator and commas for thousands:'1.34 kB'→'1,000,000 YB'
FOLLOW_UPS:
- How does fixedWidth padding affect locale formatting?
- What happens with minimumFractionDigits and locale options?
- Can you combine locale with bits and binary options?
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.