The localization package provides methods to format dates, times, numbers, and prices according to the rules of a specific locale. For typography rules, see Microtypography.
#Dates
By default, we always display the date short with abbreviation. We never use other date formats, outside of the defined ones.
- The year is not abbreviated.
- The year is displayed when, the date spans across a year change or it's stored for a longer period (timestamp).
- We always remove the leading "0" from the date numbers
- For the
short with abbreviationformat, the abbreviations dot is removed. - In EU countries the date format is always in the format of the main language of the country (e.g. all languages in France are formatted the way
fr-FRis).
| Name | Type | Default | Description | Controls |
|---|---|---|---|---|
| date * | Date | number | string | - | Target date to format | |
| locale * | "de-AT" | "de-BE" | "de-CH" | "de-DE" | "de-FR" | "de-IT" | "de-LU" | "de-NL" | "en-AT" | "en-BE" | "en-CH" | "en-DE" | "en-FR" | "en-IT" | "en-LU" | "en-NL" | "fr-AT" | "fr-BE" | "fr-CH" | "fr-DE" | "fr-FR" | "fr-IT" | "fr-LU" | "fr-NL" | "it-AT" | "it-BE" | "it-CH" | "it-DE" | "it-FR" | "it-IT" | "it-LU" | "it-NL" | "nl-AT" | "nl-BE" | "nl-CH" | "nl-DE" | "nl-FR" | "nl-IT" | "nl-LU" | "nl-NL" | - | Used locale for formatting | |
| timeZone * | "Europe/Amsterdam" | "Europe/Berlin" | "Europe/Brussels" | "Europe/Luxembourg" | "Europe/Paris" | "Europe/Rome" | "Europe/Vienna" | "Europe/Zurich" | - | TimeZone | |
| options | { variant: "medium" } | { variant: "short"; weekday: "long","short" } | - | Formatting options |
#Short with abbreviation
The default date format is short with abbreviation including the abbrevated da of the week.
| Sa, 31.12. | Di, 1.2. | So, 30.1. | Do, 1.12. | |
|---|---|---|---|---|
de-AT | Sa, 31.12. | Di, 1.2. | So, 30.1. | Do, 1.12. |
en-AT | Sat, 31.12. | Tue, 1.2. | Sun, 30.1. | Thu, 1.12. |
de-BE | Sa, 31/12 | Di, 1/2 | So, 30/1 | Do, 1/12 |
en-BE | Sat, 31/12 | Tue, 1/2 | Sun, 30/1 | Thu, 1/12 |
fr-BE | sam, 31/12 | mar, 1/2 | dim, 30/1 | jeu, 1/12 |
nl-BE | za, 31/12 | di, 1/2 | zo, 30/1 | do, 1/12 |
de-CH | Sa, 31.12. | Di, 1.2. | So, 30.1. | Do, 1.12. |
en-CH | Sat, 31.12. | Tue, 1.2. | Sun, 30.1. | Thu, 1.12. |
fr-CH | sam, 31/12 | mar, 1/2 | dim, 30/1 | jeu, 1/12 |
it-CH | sab, 31.12. | mar, 1.2. | dom, 30.1. | gio, 1.12. |
de-DE | Sa, 31.12. | Di, 1.2. | So, 30.1. | Do, 1.12. |
en-DE | Sat, 31.12. | Tue, 1.2. | Sun, 30.1. | Thu, 1.12. |
en-FR | Sat, 31/12 | Tue, 1/2 | Sun, 30/1 | Thu, 1/12 |
fr-FR | sam, 31/12 | mar, 1/2 | dim, 30/1 | jeu, 1/12 |
en-IT | Sat, 31/12 | Tue, 1/2 | Sun, 30/1 | Thu, 1/12 |
it-IT | sab, 31/12 | mar, 1/2 | dom, 30/1 | gio, 1/12 |
de-NL | Sa, 31-12 | Di, 1-2 | So, 30-1 | Do, 1-12 |
en-NL | Sat, 31-12 | Tue, 1-2 | Sun, 30-1 | Thu, 1-12 |
nl-NL | za, 31-12 | di, 1-2 | zo, 30-1 | do, 1-12 |
#Medium date
In some cases we use the date medium, for example if a date range is spaning over new year's eve.
- The abbreviated weekday is removed if the year is displayed
- The year is displayed when the two dates in a range span a change of year
Note: There is a shorthand method for medium dates called formatMediumDate().
It works exactly the same as formatDate() but with a hardcoded
variant: medium in the options.
| 31.12.2022 | 1.2.2022 | 30.1.2022 | 1.12.2022 | |
|---|---|---|---|---|
de-AT | 31.12.2022 | 1.2.2022 | 30.1.2022 | 1.12.2022 |
en-AT | 31.12.2022 | 1.2.2022 | 30.1.2022 | 1.12.2022 |
de-BE | 31/12/2022 | 1/2/2022 | 30/1/2022 | 1/12/2022 |
en-BE | 31/12/2022 | 1/2/2022 | 30/1/2022 | 1/12/2022 |
fr-BE | 31/12/2022 | 1/2/2022 | 30/1/2022 | 1/12/2022 |
nl-BE | 31/12/2022 | 1/2/2022 | 30/1/2022 | 1/12/2022 |
de-CH | 31.12.2022 | 1.2.2022 | 30.1.2022 | 1.12.2022 |
en-CH | 31.12.2022 | 1.2.2022 | 30.1.2022 | 1.12.2022 |
fr-CH | 31/12/2022 | 1/2/2022 | 30/1/2022 | 1/12/2022 |
it-CH | 31.12.2022 | 1.2.2022 | 30.1.2022 | 1.12.2022 |
de-DE | 31.12.2022 | 1.2.2022 | 30.1.2022 | 1.12.2022 |
en-DE | 31.12.2022 | 1.2.2022 | 30.1.2022 | 1.12.2022 |
en-FR | 31/12/2022 | 1/2/2022 | 30/1/2022 | 1/12/2022 |
fr-FR | 31/12/2022 | 1/2/2022 | 30/1/2022 | 1/12/2022 |
en-IT | 31/12/2022 | 1/2/2022 | 30/1/2022 | 1/12/2022 |
it-IT | 31/12/2022 | 1/2/2022 | 30/1/2022 | 1/12/2022 |
de-NL | 31-12-2022 | 1-2-2022 | 30-1-2022 | 1-12-2022 |
en-NL | 31-12-2022 | 1-2-2022 | 30-1-2022 | 1-12-2022 |
nl-NL | 31-12-2022 | 1-2-2022 | 30-1-2022 | 1-12-2022 |
#Dates in React components
In react components, the useLocalization() hook provides formatDate, by using the hook, there is no need to provide a locale.
import { useLocalization } from "@segments/localization";
const MediumDate = () => {
const { formatDate } = useLocalization();
return `Date: ${formatDate(date, { variant: "medium" })}`;
};
#Dates outside of React components
Outside of React components, the formatDate() method requires a locale.
import { formatDate, formatMediumDate } from "@segments/localization";
// usage with shorthand method
formatMediumDate(new Date(), "de-CH", "Europe/Zurich");
// regular usage
formatDate("2023-05-26", "de-CH", "Europe/Zurich");
#Chart-specific date formatting
This function is intended for chart-specific use cases only, where space
constraints require abbreviated date formats. For regular date formatting, use
formatDate instead.
For data visualizations (charts, graphs, infographics) where space is constrained,
use formatDateForChart. This function provides abbreviated month formats optimized
for chart axes and labels.
| Format | Description | Example (de-CH) |
|---|---|---|
month-short | Abbreviated month only | "Okt" |
day-month-short | Day + abbreviated month | "12. Okt." |
#Chart-specific dates outside of React components
Outside of React components, the formatDateForChart() method can be used directly, by providing a locale and timezone.
import { formatDateForChart } from "@segments/localization";
formatDateForChart(date, locale, timeZone, "month-short");
formatDateForChart(date, locale, timeZone, "day-month-short");
#Chart-specific dates in React components
In React components, the useLocalization() hook provides formatDateForChart, by using the hook, there is no need to provide a locale or timezone.
import { useLocalization } from "@segments/localization";
const ChartAxisLabel = ({ date }: { date: Date }) => {
const { formatDateForChart } = useLocalization();
return formatDateForChart(date, "month-short");
};
#Time
Currently all locales use the same time format.
| Name | Type | Default | Description | Controls |
|---|---|---|---|---|
| date * | Date | number | string | - | Target date to format | |
| locale * | "de-AT" | "de-BE" | "de-CH" | "de-DE" | "de-FR" | "de-IT" | "de-LU" | "de-NL" | "en-AT" | "en-BE" | "en-CH" | "en-DE" | "en-FR" | "en-IT" | "en-LU" | "en-NL" | "fr-AT" | "fr-BE" | "fr-CH" | "fr-DE" | "fr-FR" | "fr-IT" | "fr-LU" | "fr-NL" | "it-AT" | "it-BE" | "it-CH" | "it-DE" | "it-FR" | "it-IT" | "it-LU" | "it-NL" | "nl-AT" | "nl-BE" | "nl-CH" | "nl-DE" | "nl-FR" | "nl-IT" | "nl-LU" | "nl-NL" | - | Used locale for formatting | |
| timeZone * | string | - | TimeZone |
#Time format
| 01:00 | 02:00 | 11:00 | 13:05 | 00:45 | |
|---|---|---|---|---|---|
de-AT | 01:00 | 02:00 | 11:00 | 13:05 | 00:45 |
en-AT | 01:00 | 02:00 | 11:00 | 13:05 | 00:45 |
de-BE | 01:00 | 02:00 | 11:00 | 13:05 | 00:45 |
en-BE | 01:00 | 02:00 | 11:00 | 13:05 | 00:45 |
fr-BE | 01:00 | 02:00 | 11:00 | 13:05 | 00:45 |
nl-BE | 01:00 | 02:00 | 11:00 | 13:05 | 00:45 |
de-CH | 01:00 | 02:00 | 11:00 | 13:05 | 00:45 |
en-CH | 01:00 | 02:00 | 11:00 | 13:05 | 00:45 |
fr-CH | 01:00 | 02:00 | 11:00 | 13:05 | 00:45 |
it-CH | 01:00 | 02:00 | 11:00 | 13:05 | 00:45 |
de-DE | 01:00 | 02:00 | 11:00 | 13:05 | 00:45 |
en-DE | 01:00 | 02:00 | 11:00 | 13:05 | 00:45 |
en-FR | 01:00 | 02:00 | 11:00 | 13:05 | 00:45 |
fr-FR | 01:00 | 02:00 | 11:00 | 13:05 | 00:45 |
en-IT | 01:00 | 02:00 | 11:00 | 13:05 | 00:45 |
it-IT | 01:00 | 02:00 | 11:00 | 13:05 | 00:45 |
de-NL | 01:00 | 02:00 | 11:00 | 13:05 | 00:45 |
en-NL | 01:00 | 02:00 | 11:00 | 13:05 | 00:45 |
nl-NL | 01:00 | 02:00 | 11:00 | 13:05 | 00:45 |
#Time ranges
Time ranges are connected by the en-dash character \u2013 without any spaces, example 01:00–02:35
| Name | Type | Default | Description | Controls |
|---|---|---|---|---|
| endDate * | Date | number | string | - | End date to format | |
| locale * | "de-AT" | "de-BE" | "de-CH" | "de-DE" | "de-FR" | "de-IT" | "de-LU" | "de-NL" | "en-AT" | "en-BE" | "en-CH" | "en-DE" | "en-FR" | "en-IT" | "en-LU" | "en-NL" | "fr-AT" | "fr-BE" | "fr-CH" | "fr-DE" | "fr-FR" | "fr-IT" | "fr-LU" | "fr-NL" | "it-AT" | "it-BE" | "it-CH" | "it-DE" | "it-FR" | "it-IT" | "it-LU" | "it-NL" | "nl-AT" | "nl-BE" | "nl-CH" | "nl-DE" | "nl-FR" | "nl-IT" | "nl-LU" | "nl-NL" | - | Used locale for formatting | |
| startDate * | Date | number | string | - | Start date to format | |
| timeZone * | "Europe/Amsterdam" | "Europe/Berlin" | "Europe/Brussels" | "Europe/Luxembourg" | "Europe/Paris" | "Europe/Rome" | "Europe/Vienna" | "Europe/Zurich" | - | TimeZone |
#Time range format
| 01:00 – 02:00 | 02:00 – 03:00 | 11:00 – 12:00 | 13:05 – 14:05 | 00:45 – 01:45 | |
|---|---|---|---|---|---|
de-AT | 01:00 – 02:00 | 02:00 – 03:00 | 11:00 – 12:00 | 13:05 – 14:05 | 00:45 – 01:45 |
en-AT | 01:00 – 02:00 | 02:00 – 03:00 | 11:00 – 12:00 | 13:05 – 14:05 | 00:45 – 01:45 |
de-BE | 01:00 – 02:00 | 02:00 – 03:00 | 11:00 – 12:00 | 13:05 – 14:05 | 00:45 – 01:45 |
en-BE | 01:00 – 02:00 | 02:00 – 03:00 | 11:00 – 12:00 | 13:05 – 14:05 | 00:45 – 01:45 |
fr-BE | 01:00 – 02:00 | 02:00 – 03:00 | 11:00 – 12:00 | 13:05 – 14:05 | 00:45 – 01:45 |
nl-BE | 01:00 – 02:00 | 02:00 – 03:00 | 11:00 – 12:00 | 13:05 – 14:05 | 00:45 – 01:45 |
de-CH | 01:00 – 02:00 | 02:00 – 03:00 | 11:00 – 12:00 | 13:05 – 14:05 | 00:45 – 01:45 |
en-CH | 01:00 – 02:00 | 02:00 – 03:00 | 11:00 – 12:00 | 13:05 – 14:05 | 00:45 – 01:45 |
fr-CH | 01:00 – 02:00 | 02:00 – 03:00 | 11:00 – 12:00 | 13:05 – 14:05 | 00:45 – 01:45 |
it-CH | 01:00 – 02:00 | 02:00 – 03:00 | 11:00 – 12:00 | 13:05 – 14:05 | 00:45 – 01:45 |
de-DE | 01:00 – 02:00 | 02:00 – 03:00 | 11:00 – 12:00 | 13:05 – 14:05 | 00:45 – 01:45 |
en-DE | 01:00 – 02:00 | 02:00 – 03:00 | 11:00 – 12:00 | 13:05 – 14:05 | 00:45 – 01:45 |
en-FR | 01:00 – 02:00 | 02:00 – 03:00 | 11:00 – 12:00 | 13:05 – 14:05 | 00:45 – 01:45 |
fr-FR | 01:00 – 02:00 | 02:00 – 03:00 | 11:00 – 12:00 | 13:05 – 14:05 | 00:45 – 01:45 |
en-IT | 01:00 – 02:00 | 02:00 – 03:00 | 11:00 – 12:00 | 13:05 – 14:05 | 00:45 – 01:45 |
it-IT | 01:00 – 02:00 | 02:00 – 03:00 | 11:00 – 12:00 | 13:05 – 14:05 | 00:45 – 01:45 |
de-NL | 01:00 – 02:00 | 02:00 – 03:00 | 11:00 – 12:00 | 13:05 – 14:05 | 00:45 – 01:45 |
en-NL | 01:00 – 02:00 | 02:00 – 03:00 | 11:00 – 12:00 | 13:05 – 14:05 | 00:45 – 01:45 |
nl-NL | 01:00 – 02:00 | 02:00 – 03:00 | 11:00 – 12:00 | 13:05 – 14:05 | 00:45 – 01:45 |
#Time in React components
In React components, the useLocalization() hook provides formatTime, formatTimeRange, by using the hook, there is no need to provide a locale.
import { useLocalization } from "@segments/localization";
const TimeRange = () => {
const { formatTimeRange } = useLocalization();
return `Time range: ${formatTimeRange(startDate, endDate)}`;
};
#Time outside of React components
Outside of React components, the formatTime() or formatTimeRange() method can be used directly, by providing a locale and a time zone.
formatTime(new Date(), "de-CH", "Europe/Zurich");
#Relative time
Describes the timespan between now and a past date, in a human-readable format.
- The relative time is always translated, into the current locale.
- Examples: "2 hours ago" or "10 years ago".
| Name | Type | Default | Description | Controls |
|---|---|---|---|---|
| date * | Date | number | string | - | Target date to format | |
| locale * | "de-AT" | "de-BE" | "de-CH" | "de-DE" | "de-FR" | "de-IT" | "de-LU" | "de-NL" | "en-AT" | "en-BE" | "en-CH" | "en-DE" | "en-FR" | "en-IT" | "en-LU" | "en-NL" | "fr-AT" | "fr-BE" | "fr-CH" | "fr-DE" | "fr-FR" | "fr-IT" | "fr-LU" | "fr-NL" | "it-AT" | "it-BE" | "it-CH" | "it-DE" | "it-FR" | "it-IT" | "it-LU" | "it-NL" | "nl-AT" | "nl-BE" | "nl-CH" | "nl-DE" | "nl-FR" | "nl-IT" | "nl-LU" | "nl-NL" | - | Used locale for formatting | |
| now * | Date | number | string | - | Used locale for formatting | |
| timeZone * | string | - | TimeZone |
#Examples by locale
de-CH | en-CH | fr-FR | it-IT | nl-NL | |
|---|---|---|---|---|---|
| in 10 days | in 10 Tagen | in 10 days | dans 10 jours | tra 10 giorni | over 10 dagen |
| in 2 days | übermorgen | day after tomorrow | après-demain | dopodomani | overmorgen |
| in 1 day | morgen | tomorrow | demain | domani | morgen |
| now, until midnight | heute | today | aujourd'hui | oggi | vandaag |
| past 60 seconds | gerade eben | just now | à l'instant | proprio ora | zojuist |
| minutes ago | vor einer Minute | 1 minute ago | il y a une minute | 1 minuto fa | 1 minuut geleden |
| 10 minutes ago | vor 10 Minuten | 10 minutes ago | il y a 10 minutes | 10 minuti fa | 10 minuten geleden |
| 1 hour ago | vor einer Stunde | 1 hour ago | il y a une heure | 1 ora fa | 1 uur geleden |
| 10 hours ago | vor 10 Stunden | 10 hours ago | il y a 10 heures | 10 ore fa | 10 uren geleden |
| 1 day ago | vor einem Tag | 1 day ago | il y a un jour | 1 giorno fa | 1 dag geleden |
| 6 days ago | vor 6 Tagen | 6 days ago | il y a 6 jours | 6 giorni fa | 6 dagen geleden |
| 1 week ago | vor einer Woche | 1 week ago | il y a une semaine | 1 settimana fa | 1 week geleden |
| 3 weeks ago | vor 3 Wochen | 3 weeks ago | il y a 3 semaines | 3 settimane fa | 3 weken geleden |
| 1 month ago | vor einem Monat | 1 month ago | il y a un mois | 1 mese fa | 1 maand geleden |
| 10 months ago | vor 10 Monaten | 10 months ago | il y a 10 mois | 10 mesi fa | 10 maanden geleden |
| 1 year ago | vor einem Jahr | 1 year ago | il y a un an | 1 anno fa | 1 jaar geleden |
| 10 years ago | vor 10 Jahren | 10 years ago | il y a 10 ans | 10 anni fa | 10 jaren geleden |
#Numbers
Numbers refer to general numerical values such as quantities, sizes, or measurements.
- Grouping numbers starts at 10 000, meaning 9999 and lower, are not grouped.
- Grouping separator is the narrow no-break space character
U+202F, example: 15 500 - Inches, degrees and percentages hav no space between the number and the unit.
- All locales use the same grouping separator.
| Name | Type | Default | Description | Controls |
|---|---|---|---|---|
| actual * | number | - | Target number to format | |
| locale * | "de-AT" | "de-BE" | "de-CH" | "de-DE" | "de-FR" | "de-IT" | "de-LU" | "de-NL" | "en-AT" | "en-BE" | "en-CH" | "en-DE" | "en-FR" | "en-IT" | "en-LU" | "en-NL" | "fr-AT" | "fr-BE" | "fr-CH" | "fr-DE" | "fr-FR" | "fr-IT" | "fr-LU" | "fr-NL" | "it-AT" | "it-BE" | "it-CH" | "it-DE" | "it-FR" | "it-IT" | "it-LU" | "it-NL" | "nl-AT" | "nl-BE" | "nl-CH" | "nl-DE" | "nl-FR" | "nl-IT" | "nl-LU" | "nl-NL" | - | Used locale for formatting | |
| options * | FormatNumberOptions | - | Formatting options |
#Number format
| 20 | 20.56 | 2000 | 20000 | 200000.56 | |
|---|---|---|---|---|---|
de-AT | 20 | 20,56 | 2000 | 20 000 | 200 000,56 |
en-AT | 20 | 20,56 | 2000 | 20 000 | 200 000,56 |
de-BE | 20 | 20,56 | 2000 | 20 000 | 200 000,56 |
en-BE | 20 | 20,56 | 2000 | 20 000 | 200 000,56 |
fr-BE | 20 | 20,56 | 2000 | 20 000 | 200 000,56 |
nl-BE | 20 | 20,56 | 2000 | 20 000 | 200 000,56 |
de-CH | 20 | 20.56 | 2000 | 20 000 | 200 000.56 |
en-CH | 20 | 20.56 | 2000 | 20 000 | 200 000.56 |
fr-CH | 20 | 20.56 | 2000 | 20 000 | 200 000.56 |
it-CH | 20 | 20.56 | 2000 | 20 000 | 200 000.56 |
de-DE | 20 | 20,56 | 2000 | 20 000 | 200 000,56 |
en-DE | 20 | 20,56 | 2000 | 20 000 | 200 000,56 |
en-FR | 20 | 20,56 | 2000 | 20 000 | 200 000,56 |
fr-FR | 20 | 20,56 | 2000 | 20 000 | 200 000,56 |
en-IT | 20 | 20,56 | 2000 | 20 000 | 200 000,56 |
it-IT | 20 | 20,56 | 2000 | 20 000 | 200 000,56 |
de-NL | 20 | 20,56 | 2000 | 20 000 | 200 000,56 |
en-NL | 20 | 20,56 | 2000 | 20 000 | 200 000,56 |
nl-NL | 20 | 20,56 | 2000 | 20 000 | 200 000,56 |
#Number format with units
| 20 | 20.56 | 2000 | 20000 | 200000.56 | |
|---|---|---|---|---|---|
de-AT | 20 mAh | 20,56 mAh | 2000 mAh | 20 000 mAh | 200 000,56 mAh |
en-AT | 20 mAh | 20,56 mAh | 2000 mAh | 20 000 mAh | 200 000,56 mAh |
de-BE | 20 mAh | 20,56 mAh | 2000 mAh | 20 000 mAh | 200 000,56 mAh |
en-BE | 20 mAh | 20,56 mAh | 2000 mAh | 20 000 mAh | 200 000,56 mAh |
fr-BE | 20 mAh | 20,56 mAh | 2000 mAh | 20 000 mAh | 200 000,56 mAh |
nl-BE | 20 mAh | 20,56 mAh | 2000 mAh | 20 000 mAh | 200 000,56 mAh |
de-CH | 20 mAh | 20.56 mAh | 2000 mAh | 20 000 mAh | 200 000.56 mAh |
en-CH | 20 mAh | 20.56 mAh | 2000 mAh | 20 000 mAh | 200 000.56 mAh |
fr-CH | 20 mAh | 20.56 mAh | 2000 mAh | 20 000 mAh | 200 000.56 mAh |
it-CH | 20 mAh | 20.56 mAh | 2000 mAh | 20 000 mAh | 200 000.56 mAh |
de-DE | 20 mAh | 20,56 mAh | 2000 mAh | 20 000 mAh | 200 000,56 mAh |
en-DE | 20 mAh | 20,56 mAh | 2000 mAh | 20 000 mAh | 200 000,56 mAh |
en-FR | 20 mAh | 20,56 mAh | 2000 mAh | 20 000 mAh | 200 000,56 mAh |
fr-FR | 20 mAh | 20,56 mAh | 2000 mAh | 20 000 mAh | 200 000,56 mAh |
en-IT | 20 mAh | 20,56 mAh | 2000 mAh | 20 000 mAh | 200 000,56 mAh |
it-IT | 20 mAh | 20,56 mAh | 2000 mAh | 20 000 mAh | 200 000,56 mAh |
de-NL | 20 mAh | 20,56 mAh | 2000 mAh | 20 000 mAh | 200 000,56 mAh |
en-NL | 20 mAh | 20,56 mAh | 2000 mAh | 20 000 mAh | 200 000,56 mAh |
nl-NL | 20 mAh | 20,56 mAh | 2000 mAh | 20 000 mAh | 200 000,56 mAh |
#Number format with spaceless units
| 20 | 20.56 | 2000 | 20000 | 200000.56 | |
|---|---|---|---|---|---|
de-AT | 20" | 20,56" | 2000" | 20 000" | 200 000,56" |
en-AT | 20" | 20,56" | 2000" | 20 000" | 200 000,56" |
de-BE | 20" | 20,56" | 2000" | 20 000" | 200 000,56" |
en-BE | 20" | 20,56" | 2000" | 20 000" | 200 000,56" |
fr-BE | 20" | 20,56" | 2000" | 20 000" | 200 000,56" |
nl-BE | 20" | 20,56" | 2000" | 20 000" | 200 000,56" |
de-CH | 20" | 20.56" | 2000" | 20 000" | 200 000.56" |
en-CH | 20" | 20.56" | 2000" | 20 000" | 200 000.56" |
fr-CH | 20" | 20.56" | 2000" | 20 000" | 200 000.56" |
it-CH | 20" | 20.56" | 2000" | 20 000" | 200 000.56" |
de-DE | 20" | 20,56" | 2000" | 20 000" | 200 000,56" |
en-DE | 20" | 20,56" | 2000" | 20 000" | 200 000,56" |
en-FR | 20" | 20,56" | 2000" | 20 000" | 200 000,56" |
fr-FR | 20" | 20,56" | 2000" | 20 000" | 200 000,56" |
en-IT | 20" | 20,56" | 2000" | 20 000" | 200 000,56" |
it-IT | 20" | 20,56" | 2000" | 20 000" | 200 000,56" |
de-NL | 20" | 20,56" | 2000" | 20 000" | 200 000,56" |
en-NL | 20" | 20,56" | 2000" | 20 000" | 200 000,56" |
nl-NL | 20" | 20,56" | 2000" | 20 000" | 200 000,56" |
#Number ranges
| Name | Type | Default | Description | Controls |
|---|---|---|---|---|
| from * | number | - | from number to format | |
| locale * | "de-AT" | "de-BE" | "de-CH" | "de-DE" | "de-FR" | "de-IT" | "de-LU" | "de-NL" | "en-AT" | "en-BE" | "en-CH" | "en-DE" | "en-FR" | "en-IT" | "en-LU" | "en-NL" | "fr-AT" | "fr-BE" | "fr-CH" | "fr-DE" | "fr-FR" | "fr-IT" | "fr-LU" | "fr-NL" | "it-AT" | "it-BE" | "it-CH" | "it-DE" | "it-FR" | "it-IT" | "it-LU" | "it-NL" | "nl-AT" | "nl-BE" | "nl-CH" | "nl-DE" | "nl-FR" | "nl-IT" | "nl-LU" | "nl-NL" | - | Used locale for formatting | |
| options * | FormatNumberOptions | - | Formatting options | |
| to * | number | - | to number to format |
#Number range format
| 20 – 40 | 20.56 – 41.12 | 2000 – 4000 | 20 000 – 40 000 | 200 000.56 – 400 001.12 | |
|---|---|---|---|---|---|
de-AT | 20 – 40 | 20,56 – 41,12 | 2000 – 4000 | 20 000 – 40 000 | 200 000,56 – 400 001,12 |
en-AT | 20 – 40 | 20,56 – 41,12 | 2000 – 4000 | 20 000 – 40 000 | 200 000,56 – 400 001,12 |
de-BE | 20 – 40 | 20,56 – 41,12 | 2000 – 4000 | 20 000 – 40 000 | 200 000,56 – 400 001,12 |
en-BE | 20 – 40 | 20,56 – 41,12 | 2000 – 4000 | 20 000 – 40 000 | 200 000,56 – 400 001,12 |
fr-BE | 20 – 40 | 20,56 – 41,12 | 2000 – 4000 | 20 000 – 40 000 | 200 000,56 – 400 001,12 |
nl-BE | 20 – 40 | 20,56 – 41,12 | 2000 – 4000 | 20 000 – 40 000 | 200 000,56 – 400 001,12 |
de-CH | 20 – 40 | 20.56 – 41.12 | 2000 – 4000 | 20 000 – 40 000 | 200 000.56 – 400 001.12 |
en-CH | 20 – 40 | 20.56 – 41.12 | 2000 – 4000 | 20 000 – 40 000 | 200 000.56 – 400 001.12 |
fr-CH | 20 – 40 | 20.56 – 41.12 | 2000 – 4000 | 20 000 – 40 000 | 200 000.56 – 400 001.12 |
it-CH | 20 – 40 | 20.56 – 41.12 | 2000 – 4000 | 20 000 – 40 000 | 200 000.56 – 400 001.12 |
de-DE | 20 – 40 | 20,56 – 41,12 | 2000 – 4000 | 20 000 – 40 000 | 200 000,56 – 400 001,12 |
en-DE | 20 – 40 | 20,56 – 41,12 | 2000 – 4000 | 20 000 – 40 000 | 200 000,56 – 400 001,12 |
en-FR | 20 – 40 | 20,56 – 41,12 | 2000 – 4000 | 20 000 – 40 000 | 200 000,56 – 400 001,12 |
fr-FR | 20 – 40 | 20,56 – 41,12 | 2000 – 4000 | 20 000 – 40 000 | 200 000,56 – 400 001,12 |
en-IT | 20 – 40 | 20,56 – 41,12 | 2000 – 4000 | 20 000 – 40 000 | 200 000,56 – 400 001,12 |
it-IT | 20 – 40 | 20,56 – 41,12 | 2000 – 4000 | 20 000 – 40 000 | 200 000,56 – 400 001,12 |
de-NL | 20 – 40 | 20,56 – 41,12 | 2000 – 4000 | 20 000 – 40 000 | 200 000,56 – 400 001,12 |
en-NL | 20 – 40 | 20,56 – 41,12 | 2000 – 4000 | 20 000 – 40 000 | 200 000,56 – 400 001,12 |
nl-NL | 20 – 40 | 20,56 – 41,12 | 2000 – 4000 | 20 000 – 40 000 | 200 000,56 – 400 001,12 |
#Numbers in React components
In React components, the useLocalization() hook provides formatNumber, by using the hook, there is no need to provide a locale.
import { useLocalization } from "@segments/localization";
const MyNumberComponent: FunctionComponent<{ sum: number }> = ({ sum }) => {
const { formatNumber } = useLocalization();
return `Number: ${formatNumber(sum)}`;
};
#Numbers outside of React components
Outside of React components, the formatNumber() method can be used directly, by providing a locale.
import { formatNumber } from "@segments/localization";
const formattedNumber = formatNumber(20.56, "de-CH");
#Price
- Currency is always prefixed to the number, example: CHF 20.56.
- Decimal places without value are always represented with .– example: CHF 50.–
- Grouping prices stars 10 000, meaning 9999 and lower, are not grouped.
- Grouping separator is narrow no-break space
U+202F, example: CHF 15 500.56
| Name | Type | Default | Description | Controls |
|---|---|---|---|---|
| locale * | "de-AT" | "de-BE" | "de-CH" | "de-DE" | "de-FR" | "de-IT" | "de-LU" | "de-NL" | "en-AT" | "en-BE" | "en-CH" | "en-DE" | "en-FR" | "en-IT" | "en-LU" | "en-NL" | "fr-AT" | "fr-BE" | "fr-CH" | "fr-DE" | "fr-FR" | "fr-IT" | "fr-LU" | "fr-NL" | "it-AT" | "it-BE" | "it-CH" | "it-DE" | "it-FR" | "it-IT" | "it-LU" | "it-NL" | "nl-AT" | "nl-BE" | "nl-CH" | "nl-DE" | "nl-FR" | "nl-IT" | "nl-LU" | "nl-NL" | - | Used locale for formatting | |
| options * | FormatPriceOptions | - | Formatting options | |
| price * | number | - | Target price to format |
#Price format without currency
| 20 | 20.56 | 2000 | 20000 | 200000.56 | -200000.56 | |
|---|---|---|---|---|---|---|
de-AT | 20,– | 20,56 | 2000,– | 20 000,– | 200 000,56 | -200 000,56 |
en-AT | 20,– | 20,56 | 2000,– | 20 000,– | 200 000,56 | -200 000,56 |
de-BE | 20,– | 20,56 | 2000,– | 20 000,– | 200 000,56 | -200 000,56 |
en-BE | 20,– | 20,56 | 2000,– | 20 000,– | 200 000,56 | -200 000,56 |
fr-BE | 20,– | 20,56 | 2000,– | 20 000,– | 200 000,56 | -200 000,56 |
nl-BE | 20,– | 20,56 | 2000,– | 20 000,– | 200 000,56 | -200 000,56 |
de-CH | 20.– | 20.56 | 2000.– | 20 000.– | 200 000.56 | -200 000.56 |
en-CH | 20.– | 20.56 | 2000.– | 20 000.– | 200 000.56 | -200 000.56 |
fr-CH | 20.– | 20.56 | 2000.– | 20 000.– | 200 000.56 | -200 000.56 |
it-CH | 20.– | 20.56 | 2000.– | 20 000.– | 200 000.56 | -200 000.56 |
de-DE | 20,– | 20,56 | 2000,– | 20 000,– | 200 000,56 | -200 000,56 |
en-DE | 20,– | 20,56 | 2000,– | 20 000,– | 200 000,56 | -200 000,56 |
en-FR | 20,– | 20,56 | 2000,– | 20 000,– | 200 000,56 | -200 000,56 |
fr-FR | 20,– | 20,56 | 2000,– | 20 000,– | 200 000,56 | -200 000,56 |
en-IT | 20,– | 20,56 | 2000,– | 20 000,– | 200 000,56 | -200 000,56 |
it-IT | 20,– | 20,56 | 2000,– | 20 000,– | 200 000,56 | -200 000,56 |
de-NL | 20,– | 20,56 | 2000,– | 20 000,– | 200 000,56 | -200 000,56 |
en-NL | 20,– | 20,56 | 2000,– | 20 000,– | 200 000,56 | -200 000,56 |
nl-NL | 20,– | 20,56 | 2000,– | 20 000,– | 200 000,56 | -200 000,56 |
#Price format with currency
| 20 | 20.56 | 2000 | 20000 | 200000.56 | -200000.56 | |
|---|---|---|---|---|---|---|
de-AT | EUR 20,– | EUR 20,56 | EUR 2000,– | EUR 20 000,– | EUR 200 000,56 | EUR -200 000,56 |
en-AT | EUR 20,– | EUR 20,56 | EUR 2000,– | EUR 20 000,– | EUR 200 000,56 | EUR -200 000,56 |
de-BE | EUR 20,– | EUR 20,56 | EUR 2000,– | EUR 20 000,– | EUR 200 000,56 | EUR -200 000,56 |
en-BE | EUR 20,– | EUR 20,56 | EUR 2000,– | EUR 20 000,– | EUR 200 000,56 | EUR -200 000,56 |
fr-BE | EUR 20,– | EUR 20,56 | EUR 2000,– | EUR 20 000,– | EUR 200 000,56 | EUR -200 000,56 |
nl-BE | EUR 20,– | EUR 20,56 | EUR 2000,– | EUR 20 000,– | EUR 200 000,56 | EUR -200 000,56 |
de-CH | CHF 20.– | CHF 20.56 | CHF 2000.– | CHF 20 000.– | CHF 200 000.56 | CHF -200 000.56 |
en-CH | CHF 20.– | CHF 20.56 | CHF 2000.– | CHF 20 000.– | CHF 200 000.56 | CHF -200 000.56 |
fr-CH | CHF 20.– | CHF 20.56 | CHF 2000.– | CHF 20 000.– | CHF 200 000.56 | CHF -200 000.56 |
it-CH | CHF 20.– | CHF 20.56 | CHF 2000.– | CHF 20 000.– | CHF 200 000.56 | CHF -200 000.56 |
de-DE | EUR 20,– | EUR 20,56 | EUR 2000,– | EUR 20 000,– | EUR 200 000,56 | EUR -200 000,56 |
en-DE | EUR 20,– | EUR 20,56 | EUR 2000,– | EUR 20 000,– | EUR 200 000,56 | EUR -200 000,56 |
en-FR | EUR 20,– | EUR 20,56 | EUR 2000,– | EUR 20 000,– | EUR 200 000,56 | EUR -200 000,56 |
fr-FR | EUR 20,– | EUR 20,56 | EUR 2000,– | EUR 20 000,– | EUR 200 000,56 | EUR -200 000,56 |
en-IT | EUR 20,– | EUR 20,56 | EUR 2000,– | EUR 20 000,– | EUR 200 000,56 | EUR -200 000,56 |
it-IT | EUR 20,– | EUR 20,56 | EUR 2000,– | EUR 20 000,– | EUR 200 000,56 | EUR -200 000,56 |
de-NL | EUR 20,– | EUR 20,56 | EUR 2000,– | EUR 20 000,– | EUR 200 000,56 | EUR -200 000,56 |
en-NL | EUR 20,– | EUR 20,56 | EUR 2000,– | EUR 20 000,– | EUR 200 000,56 | EUR -200 000,56 |
nl-NL | EUR 20,– | EUR 20,56 | EUR 2000,– | EUR 20 000,– | EUR 200 000,56 | EUR -200 000,56 |
#Price range
| Name | Type | Default | Description | Controls |
|---|---|---|---|---|
| from * | number | - | from price to format | |
| locale * | "de-AT" | "de-BE" | "de-CH" | "de-DE" | "de-FR" | "de-IT" | "de-LU" | "de-NL" | "en-AT" | "en-BE" | "en-CH" | "en-DE" | "en-FR" | "en-IT" | "en-LU" | "en-NL" | "fr-AT" | "fr-BE" | "fr-CH" | "fr-DE" | "fr-FR" | "fr-IT" | "fr-LU" | "fr-NL" | "it-AT" | "it-BE" | "it-CH" | "it-DE" | "it-FR" | "it-IT" | "it-LU" | "it-NL" | "nl-AT" | "nl-BE" | "nl-CH" | "nl-DE" | "nl-FR" | "nl-IT" | "nl-LU" | "nl-NL" | - | Used locale for formatting | |
| options * | Omit<FormatPriceOptions, "forbidPriceSubstitution"> | - | Formatting options | |
| to * | number | - | to price to format |
#Price range format
| 20 – 40 | 2000 – 4000 | 20 000 – 40 000 | |
|---|---|---|---|
de-AT | EUR 20 – 40 | EUR 2000 – 4000 | EUR 20 000 – 40 000 |
en-AT | EUR 20 – 40 | EUR 2000 – 4000 | EUR 20 000 – 40 000 |
de-BE | EUR 20 – 40 | EUR 2000 – 4000 | EUR 20 000 – 40 000 |
en-BE | EUR 20 – 40 | EUR 2000 – 4000 | EUR 20 000 – 40 000 |
fr-BE | EUR 20 – 40 | EUR 2000 – 4000 | EUR 20 000 – 40 000 |
nl-BE | EUR 20 – 40 | EUR 2000 – 4000 | EUR 20 000 – 40 000 |
de-CH | CHF 20 – 40 | CHF 2000 – 4000 | CHF 20 000 – 40 000 |
en-CH | CHF 20 – 40 | CHF 2000 – 4000 | CHF 20 000 – 40 000 |
fr-CH | CHF 20 – 40 | CHF 2000 – 4000 | CHF 20 000 – 40 000 |
it-CH | CHF 20 – 40 | CHF 2000 – 4000 | CHF 20 000 – 40 000 |
de-DE | EUR 20 – 40 | EUR 2000 – 4000 | EUR 20 000 – 40 000 |
en-DE | EUR 20 – 40 | EUR 2000 – 4000 | EUR 20 000 – 40 000 |
en-FR | EUR 20 – 40 | EUR 2000 – 4000 | EUR 20 000 – 40 000 |
fr-FR | EUR 20 – 40 | EUR 2000 – 4000 | EUR 20 000 – 40 000 |
en-IT | EUR 20 – 40 | EUR 2000 – 4000 | EUR 20 000 – 40 000 |
it-IT | EUR 20 – 40 | EUR 2000 – 4000 | EUR 20 000 – 40 000 |
de-NL | EUR 20 – 40 | EUR 2000 – 4000 | EUR 20 000 – 40 000 |
en-NL | EUR 20 – 40 | EUR 2000 – 4000 | EUR 20 000 – 40 000 |
nl-NL | EUR 20 – 40 | EUR 2000 – 4000 | EUR 20 000 – 40 000 |
#Prices in React components
In React components, the useLocalization() hook provides formatPrice, by using the hook, there is no need to provide a locale.
import { useLocalization } from "@segments/localization";
const MyPriceComponent: FunctionComponent<{ price: number }> = ({ price }) => {
const { formatPrice } = useLocalization();
return `Price: ${formatPrice(price)}`;
};
#Prices outside of React components
Outside of React components, the formatPrice() method can be used directly, by providing a locale.
import { formatPrice } from "@segments/localization";
const price = formatPrice(20.56, "de-CH", { currency: "CHF" });