Money & Currency Utilities - Admin Components

Note: These utilities are available since Medusa v2.21.0.

The @medusajs/dashboard/lib subpath exports the utilities that the Medusa Admin uses to format amounts and look up currency data. Use them in your admin extensions to display prices and totals the same way the Medusa Admin does.

Code
1import {2  castNumber,3  currencies,4  formatCurrency,5  getCurrencyDecimalDigits,6  getCurrencySymbol,7  getDecimalDigits,8  getLocaleAmount,9  getNativeSymbol,10  getStylizedAmount,11} from "@medusajs/dashboard/lib"

getStylizedAmount#

Formats an amount in the Medusa Admin's style, placing the currency's native symbol before the amount and the uppercase currency code after it. The Medusa Admin uses it for totals.

Code
1import { getStylizedAmount } from "@medusajs/dashboard/lib"2
3getStylizedAmount(10, "usd") // "$ 10.00 USD"

Parameters#

Loading...

Returns#

Returns a string of the formatted amount. When the amount is smaller than the currency's rounding precision, the formatted amount shows an explicit sign.


getLocaleAmount#

Formats an amount as a currency string using the browser's locale and the currency's narrow symbol.

Code
1import { getLocaleAmount } from "@medusajs/dashboard/lib"2
3getLocaleAmount(10, "usd") // "$10.00" in the en-US locale

Parameters#

Loading...

Returns#

Returns a string of the amount formatted in the browser's locale.


formatCurrency#

Formats an amount as a currency string using the browser's default locale and the currency's default symbol style.

Code
1import { formatCurrency } from "@medusajs/dashboard/lib"2
3formatCurrency(10, "usd") // "$10.00" in the en-US locale

Parameters#

Loading...

Returns#

Returns a string of the formatted amount.


getNativeSymbol#

Returns the native symbol of a currency by formatting a zero amount and stripping the digits and separators.

Code
1import { getNativeSymbol } from "@medusajs/dashboard/lib"2
3getNativeSymbol("usd") // "$"

Parameters#

Loading...

Returns#

Returns a string of the currency's native symbol.


getDecimalDigits#

Returns the number of decimal digits of a currency from the currencies object. Returns 0 when the currency isn't in the object.

Code
1import { getDecimalDigits } from "@medusajs/dashboard/lib"2
3getDecimalDigits("usd") // 2

Parameters#

Loading...

Returns#

Returns a number of the currency's decimal digits, or 0 if the currency isn't supported.


castNumber#

Converts a value entered in an input into a number, replacing a comma decimal separator with a period. Use it with a Zod schema that accepts both a string and a number.

Code
1import { castNumber } from "@medusajs/dashboard/lib"2
3castNumber("10,5") // 10.54castNumber(10.5) // 10.5

Parameters#

Loading...

Returns#

Returns a number.


currencies#

An object of the currencies that the Medusa Admin supports, keyed by uppercase currency code. Each value is a CurrencyInfo object.

Code
1import { currencies } from "@medusajs/dashboard/lib"2
3currencies.USD.name // "US Dollar"

CurrencyInfo Properties#

Loading...

getCurrencySymbol and getCurrencyDecimalDigits#

Read a currency's native symbol or number of decimal digits from the currencies object.

Warning: Both functions throw an error when the currency code isn't in the currencies object. Use getDecimalDigits instead if you need a 0 fallback.
Code
1import {2  getCurrencyDecimalDigits,3  getCurrencySymbol,4} from "@medusajs/dashboard/lib"5
6getCurrencySymbol("usd") // "$"7getCurrencyDecimalDigits("usd") // 2

Parameters#

Loading...

Returns#

Loading...
Was this page helpful?
Ask Bloom
For assistance in your development, use Claude Code Plugins or Docs MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break
⇧↵