Formatters

Helper components for formatting numeric and date values based on the current language and locale-specific conventions .

<NumericFormat> and <DateFormat> components are built on top of the Intl.NumerFormat and Intl.DateTimeFormat APIs which provide a comprhensive support for formatting numbers and date based on locale-specific conventions.

1. NumericFormat

With <NumericFormat> helper, you can easily ensure that numeric values are displayed consistently and accurtely, taking into account factors such as decimal separators, curreny symbols, and grouping separators specific to each language.

Usage

Import

To import the component you just have to use this code below.

import { NumericFormat } from '@marigold/system';

Appearance

Sorry! There are currently no variants and sizes available.

Props

PropertyTypeDefaultDescription
valuenumber | bigintnoneValue to be formatted.
tabularbooleantrueSpecifies that the digits should take the full width.
minimumFractionDigitsnumbernoneMinimum number of fraction digits to display.
maximumFractionDigitsnumbernoneMaximum number of fraction digits to display.
useGroupingbooleantrueSpecifies whether to use grouping separators (e.g., thousands separator).
compactDisplaylong | shortnone How to display the number in a compact form. Possible values are "short", "long", and "narrow"
currencystringnoneSpecifies the currency code to use when the style is set to currency
currencyDisplaystringstandardSpecifies whether to display the currency symbol or sign. Possible values are "standard" (default), "accounting", and "code"
currencySignstringnoneSpecifies whether to display the currency symbol or sign. Possible values are "standard" (default), "accounting", and "code"
stylestringnoneSpecifies the formatting style for the number. Possible values are "decimal", "currency", "percent", "unit", and "compact"

Examples

Formatted Currency Value

In this example the value passed is formatted based on the currency chosen 'USD' .

$233.00

Formatted Percentage Value

In this example the decimal value is formatted into two fraction digits percentage value .

73.33%

Formatted Numeric Value

Formats the number with a max of 2 significant digits, only the most significant digits are displayed.

value: 120,000

2. DateFormat

With <DateFormat> helper, you can easily ensure consistent and accurate display of date and time values taking into account factors such as date formats, time formas, time zones, and locale-specific conventions. It provides a way to format and localize dates and times based on the user's preferred language and region.

Usage

Import

To import the component you just have to use this code below.

import { DateFormat } from '@marigold/system';

Appearance

Sorry! There are currently no variants and sizes available.

Props

PropertyTypeDefaultDescription
valueDatenoneValue to be formatted.
tabularbooleantrueSpecifies that the digits should take the full width.
localestringHost environment's current localeSpecifies the locale or language tag to use.
dateStylestringnoneSpecifies the date formatting style.
timeStylestringnoneSpecifies the time formatting style.
weekdaystringnoneSpecifies how to display the day of the week.
yearstringnoneSpecifies how to display the year.
monthstringnoneSpecifies how to display the month.
daystringnoneSpecifies how to display the day of the month.
hourstringnoneSpecifies how to display the hour.
minutestringnoneSpecifies how to display the minute.
secondstringnoneSpecifies how to display the second.
timeZonestringnoneSpecifies the time zone to use for formatting.

Examples

Short Date Format

In this example the date is formatted using the "short" date style.

Current Date:08.02.24

Long Date Format

In this example the date is formatted using the "full" date style.

Donnerstag, 8. Februar 2024