# General Translation Platform: formatNum
URL: https://generaltranslation.com/en-US/docs/platform/core/reference/utility-functions/formatting/format-num.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: Format numbers, currency, percentages, and numeric values without a GT instance. API reference for formatNum.

[`formatNum`](/docs/platform/core/reference/gt-class-methods/formatting/format-num) is a standalone utility function from General Translation's Core library that formats numbers according to locale-specific conventions. It returns a locale-aware string for decimals, currency, percentages, and units.

## Overview [#overview]

Import `formatNum` directly from `generaltranslation` and call it with the number to format and an options object. It does not require an API key or a [GT](/docs/platform/core/reference/gt-class/constructor) instance, so use it anywhere you need one-off number formatting. For instance-based formatting that inherits the instance locale, use the [`formatNum`](/docs/platform/core/reference/gt-class-methods/formatting/format-num) method on a [`GT`](/docs/platform/core/reference/gt-class/constructor) instance instead.

```typescript
import { formatNum } from 'generaltranslation';

const formatted = formatNum(1234.56, {
  locales: 'de-DE',
  style: 'currency',
  currency: 'EUR',
});
// Returns: "1.234,56 €"
```

Signature:

```typescript
formatNum(
  number: number,
  options?: { locales?: string | string[] } & Intl.NumberFormatOptions
): string
```

## How it works [#how-it-works]

- **Underlying API.** Uses the same [`Intl.NumberFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat) as the GT class method, so all standard `Intl.NumberFormat` options are supported.
- **Locale resolution.** When `locales` is an array, locales are tried in order and the first supported locale is used. When `locales` is omitted, it falls back to the library default locale, `en`.
- **Caching.** Results are cached internally for performance across repeated locale and options combinations.

## Parameters [#parameters]

| Parameter | Description | Type | Optional | Default |
| --- | --- | --- | --- | --- |
| [`number`](#number) | The number to format. | `number` | No | — |
| [`options`](#options) | Formatting configuration, including the target locale(s) and any `Intl.NumberFormat` options. | `{ locales?: string \| string[] } & Intl.NumberFormatOptions` | Yes | `{}` |

### `number` [#number]

**Type** `number` · **Required**

The numeric value to format.

### `options` [#options]

**Type** `{ locales?: string | string[] } & Intl.NumberFormatOptions` · **Optional** · **Default** `{}`

Formatting configuration. The table lists common options exposed by the published Core types and their effective Core defaults. (See the [`Intl.NumberFormat` constructor options](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options) for supplemental standard and runtime-specific details).

| Property | Description | Type | Optional | Default |
| --- | --- | --- | --- | --- |
| `locales` | Locale(s) for formatting. Tried in order when an array is passed. | `string \| string[]` | Yes | `en` |
| `localeMatcher` | Locale matching algorithm. | `'lookup' \| 'best fit'` | Yes | `'best fit'` |
| `numberingSystem` | Numbering system, such as `latn` or `arab`. | `string` | Yes | `'latn'` |
| `style` | Number formatting style. | `'decimal' \| 'currency' \| 'percent' \| 'unit'` | Yes | `'decimal'` |
| `currency` | Currency code (required when `style` is `'currency'`). | `string` | Yes | — |
| `currencyDisplay` | How to display the currency. | `'symbol' \| 'narrowSymbol' \| 'code' \| 'name'` | Yes | `'symbol'` |
| `currencySign` | Currency sign to use. | `'standard' \| 'accounting'` | Yes | `'standard'` |
| `unit` | Unit identifier (required when `style` is `'unit'`). | `string` | Yes | — |
| `unitDisplay` | How to display the unit. | `'short' \| 'narrow' \| 'long'` | Yes | `'short'` |
| `minimumIntegerDigits` | Minimum number of integer digits (1–21). | `number` | Yes | `1` |
| `minimumFractionDigits` | Minimum fraction digits (0–100). The style affects the default. | `number` | Yes | `0` for decimal/percent; currency minor-unit digits for currency; `0` with compact defaults |
| `maximumFractionDigits` | Maximum fraction digits (0–100). The style and minimum affect the default. | `number` | Yes | `3` for decimal; `0` for percent; currency minor-unit digits for currency; `0` with compact defaults |
| `minimumSignificantDigits` | Minimum significant digits (1–21), when significant-digit rounding is active. | `number` | Yes | `1` |
| `maximumSignificantDigits` | Maximum significant digits (1–21), when significant-digit rounding is active. | `number` | Yes | `21`; `2` with compact defaults |
| `roundingPriority` | How fraction- and significant-digit settings interact. | `'auto' \| 'morePrecision' \| 'lessPrecision'` | Yes | `'auto'`; `'morePrecision'` with compact defaults |
| `notation` | Number notation format. | `'standard' \| 'scientific' \| 'engineering' \| 'compact'` | Yes | `'standard'` |
| `compactDisplay` | Compact notation display style. | `'short' \| 'long'` | Yes | `'short'` |
| `useGrouping` | Whether and when to use grouping separators. | `boolean \| 'always' \| 'auto' \| 'min2'` | Yes | `'auto'`; `'min2'` with compact notation |
| `signDisplay` | When to display the sign. | `'auto' \| 'never' \| 'always' \| 'exceptZero' \| 'negative'` | Yes | `'auto'` |
| `roundingMode` | Rounding mode. | `'ceil' \| 'floor' \| 'expand' \| 'trunc' \| 'halfCeil' \| 'halfFloor' \| 'halfExpand' \| 'halfTrunc' \| 'halfEven'` | Yes | `'halfExpand'` |
| `roundingIncrement` | Rounding increment. Non-default values require equal effective minimum and maximum fraction digits and cannot be combined with significant-digit rounding or a non-`'auto'` `roundingPriority`. | `1 \| 2 \| 5 \| 10 \| 20 \| 25 \| 50 \| 100 \| 200 \| 250 \| 500 \| 1000 \| 2000 \| 2500 \| 5000` | Yes | `1` |
| `trailingZeroDisplay` | Whether to display trailing zeros. | `'auto' \| 'stripIfInteger'` | Yes | `'auto'` |

When `notation: 'compact'` is set without any fraction- or significant-digit option, the effective digit defaults are `minimumFractionDigits: 0`, `maximumFractionDigits: 0`, `minimumSignificantDigits: 1`, and `maximumSignificantDigits: 2`. In that case, `roundingPriority` defaults to `'morePrecision'` and `useGrouping` defaults to `'min2'`.

## Returns [#returns]

**Type** `string`

The number formatted according to locale conventions.

## Examples [#examples]

```typescript
import { formatNum } from 'generaltranslation';

// Basic number formatting
console.log(formatNum(1234.567, { locales: 'en-US' }));
// Output: "1,234.567"

// German formatting
console.log(formatNum(1234.567, { locales: 'de-DE' }));
// Output: "1.234,567"
```

```typescript
// Currency formatting

// US Dollar
console.log(formatNum(1234.56, {
  locales: 'en-US',
  style: 'currency',
  currency: 'USD',
}));
// Output: "$1,234.56"

// Euro with German locale
console.log(formatNum(1234.56, {
  locales: 'de-DE',
  style: 'currency',
  currency: 'EUR',
}));
// Output: "1.234,56 €"

// Japanese Yen
console.log(formatNum(1234.56, {
  locales: 'ja-JP',
  style: 'currency',
  currency: 'JPY',
}));
// Output: "¥1,235"
```

## Notes [#notes]

- Uses the same underlying `Intl.NumberFormat` as the GT class method.
- Results are cached internally for performance with repeated locale/options combinations.
- Fallback locales are processed in order if the primary locale is not supported.
- All standard `Intl.NumberFormat` options are supported.

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
