Skip to main content

Money

The formatMoney function formats a MoneyV2 value or a same-currency price range for display. Use the function to show product prices, compare-at prices, and price ranges in the active market's locale.

Import formatMoney from @shopify/hydrogen.


Formats a price or a price range for display. Pass a MoneyV2 price, or an array of MoneyV2 prices in one currency for a range, with the active market's locale.

The returned object converts to the formatted string in template literals and string concatenation. For custom price layouts, read the parts of the formatted price. A range shows the lowest and highest prices. When every price in the range matches, the output shows one price.

The function throws an error when an amount isn't numeric, when a range is empty, or when the prices in a range use different currencies.

Anchor to money
money
| readonly []
required

A price, or an array of prices in one currency for a range.

Anchor to options
options
required

Locale and display settings.

|

The formatted price or range, which converts to a string in template literals.

Examples

TypeScript

import { formatMoney, type MoneyV2 } from "@shopify/hydrogen";

export function formatPrice(money: MoneyV2, locale = "en-US"): string {
return formatMoney(money, { locale }).toString();
}

const price = formatMoney({ amount: "19.00", currencyCode: "USD" }, { locale: "en-US" });
price.localizedString;
// "$19.00"
price.withoutTrailingZeros;
// "$19"

Was this page helpful?