Skip to content

[6.x] Number formatter#14373

Merged
jasonvarga merged 6 commits into6.xfrom
number-formatter
Mar 27, 2026
Merged

[6.x] Number formatter#14373
jasonvarga merged 6 commits into6.xfrom
number-formatter

Conversation

@jasonvarga
Copy link
Copy Markdown
Member

@jasonvarga jasonvarga commented Mar 26, 2026

This PR adds a NumberFormatter that mirrors DateFormatter which can output numbers depending on the user's locale.

import { numberFormatter } from '@statamic/cms/api';

numberFormatter.format(123456789.10);
// en does 123,456,789.10
// de does 123.456.789,10

numberFormatter.formatRange(1234, 5678);
// en does 1,234–5,678
// ja-jp does 1,234~5,678

numberFormatter.formatRange(0.1, 0.2, 'percent');
// en does 10% – 20%
// de does 10–20 %

This PR also makes DateFormatter and NumberFormatter share the same locale. If the NumberFormatter.setDefaultLocale() is used, it'll be reflected in DateFormatter and vice versa.

See this video for an example of how different numbers and dates would be rendered based on the selected locale.

CleanShot.2026-03-26.at.19.58.30.mp4

The only place where this is used at the moment is in pagination:

CleanShot 2026-03-26 at 20 24 21

@jasonvarga jasonvarga marked this pull request as ready for review March 27, 2026 00:04
@jasonvarga jasonvarga merged commit 1652e74 into 6.x Mar 27, 2026
17 checks passed
@jasonvarga jasonvarga deleted the number-formatter branch March 27, 2026 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant