Skip to content

formatCurrency

This helper function is used to format a currency value for a given locale. Intl.NumberFormat is used under the hood to format the currency.

Import

Terminal window
import { formatCurrency } from "@aeonkit/helpers";

Parameters

formatCurrency accepts a single object as a parameter with the following properties:

amount

amount

number bigint

The amount to format.

options

See the Intl.NumberFormatOptions page for more information on what can be passed in.

options?

Intl.NumberFormatOptions

The options to format the currency.

locale

See the locales page for more information on what can be passed in.

locale?

Intl.LocalesArgument

The locale to format the currency.

Default: en-US

Usage

Default

Terminal window
formatCurrency({ amount: 2390.45 })

The above would yield the following output:

Terminal window
$2,390.45

With Options

Here is an example with options:

formatCurrency({ amount: 2390.45, options: { currency: "EUR"} })

The above would yield the following output:

Terminal window
€2,390.45

Returns

The formatted currency value as a string.