Format numbers
Format Numbers
When editing .tsx files, ensure all user-facing numbers are formatted using the formatNumber utility from @tryghost/shade.
Import
import {formatNumber} from '@tryghost/shade';
When to use formatNumber
Use formatNumber() when rendering any numeric value that is displayed to the user, including:
- Member counts, visitor counts, subscriber counts
- Email engagement metrics (opens, clicks, bounces)
- Revenue amounts (combine with
centsToDollars()for monetary values) - Post analytics (views, link clicks)
- Any count or quantity shown in UI
Correct usage
<span>{formatNumber(totalMembers)}</span>
<span>{formatNumber(link.count || 0)}</span>
<span>{`${currencySymbol}${formatNumber(centsToDollars(mrr))}`}</span>
<span>{post.members > 0 ? `+${formatNumber(post.members)}` : '0'}</span>
Antipatterns to avoid
Do NOT use any of these patterns for formatting numbers in TSX files:
// BAD: raw .toLocaleString()
<span>{count.toLocaleString()}</span>
// BAD: manual Intl.NumberFormat
<span>{new Intl.NumberFormat('en-US').format(count)}</span>
// BAD: raw number without formatting
<span>{memberCount}</span>
// BAD: manual regex formatting
<span>{count.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')}</span>
Related utilities
formatPercentage()- for percentages (e.g., open rates, click rates)abbreviateNumber()- for compact notation (e.g., 1.2M, 50k)centsToDollars()- convert cents to dollars before passing toformatNumber
All are imported from @tryghost/shade.
More from tryghost/ghost
add admin api endpoint
Add a new endpoint or endpoints to Ghost's Admin API at `ghost/api/admin/**`.
84create database migration
Create a database migration to add a table, add columns to an existing table, add a setting, or otherwise change the schema of Ghost's MySQL database. Use this skill whenever the task involves modifying Ghost's database schema — including adding, removing, or renaming columns or tables, adding new settings, creating indexes, updating data, or any change that requires a migration file in ghost/core. Also use when the user references schema.js, knex-migrator, the migrations directory, or asks to "add a field" or "add a column" to any Ghost model/table. Even if the user frames it as a feature or Linear issue, if the implementation requires a schema change, this skill applies.
83commit
Commit message formatting and guidelines
4add-private-feature-flag
Use when adding a new private (developer experiments) feature flag to Ghost, including the backend registration and settings UI toggle.
1