Skip to content

fix: apply locale formatting when precision is set - #376

Merged
avoidwork merged 1 commit into
masterfrom
fix/locale-precision
Oct 21, 2026
Merged

avoidwork merged 1 commit into
masterfrom
fix/locale-precision

Conversation

@avoidwork

Copy link
Copy Markdown
Owner

Summary

When the precision option is set, the value is a string from toPrecision(), and toLocaleString() on a string is a no-op — so the locale's decimal separator was ignored. filesize(1234, { locale: "sv", precision: 2 }) returned 1.2 kB instead of 1,2 kB.

The fix coerces the string back to a number before locale formatting (only for non-zero values, so zero precision like 0.00 is retained), letting the locale formatter apply its decimal separator.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature / enhancement
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Build / dependency / tooling change
  • Test additions or updates
  • Other

Related Issues

fixes #373

Testing

npm test passes (272 tests, 100% coverage). npm run build succeeds. Added a regression test covering sv, de-DE, en-US, precision 3, and negative values.

Checklist

  • npm test passes
  • npm run build succeeds
  • 100% test coverage maintained
  • No hardcoded secrets or credentials introduced
  • Zero external dependencies added
  • ES Modules only (no CommonJS in src/)
  • JSDoc comments added/updated
  • CHANGELOG.md updated (if applicable)

Screenshots (if applicable)

N/A

@avoidwork avoidwork added the bug label Oct 21, 2026
@avoidwork avoidwork self-assigned this Oct 21, 2026
@avoidwork
avoidwork merged commit f5bd84b into master Oct 21, 2026
2 checks passed
@avoidwork
avoidwork deleted the fix/locale-precision branch October 21, 2026 21:26
@avoidwork avoidwork mentioned this pull request Oct 21, 2026
9 of 15 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Locale ignored if precision is set

1 participant