Money & Currency Utilities - Admin Components
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.
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.
Parameters#
Returns#
Returns a 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.
Parameters#
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.
Parameters#
Returns#
Returns a of the formatted amount.
getNativeSymbol#
Returns the native symbol of a currency by formatting a zero amount and stripping the digits and separators.
Parameters#
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.
Parameters#
Returns#
Returns a of the currency's decimal digits, or 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.
Parameters#
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.
CurrencyInfo Properties#
getCurrencySymbol and getCurrencyDecimalDigits
Read a currency's native symbol or number of decimal digits from the currencies object.
currencies object. Use getDecimalDigits instead if you need a 0 fallback.