Hydrogen Money
- by Shopify
- MIT license
Guide for formatting Shopify money values in Hydrogen storefronts.
npx skills add 'Shopify/hydrogen' --skill 'hydrogen-money' -a claude-code -yInstalls in this project. Add -g to install globally.
Guide for formatting Shopify money values in Hydrogen storefronts.
npx skills add 'Shopify/hydrogen' --skill 'hydrogen-money' -a claude-code -yInstalls in this project. Add -g to install globally.
Use Hydrogen's formatMoney() for Storefront API MoneyV2 values. Never build money strings by concatenating currency symbols or computing totals client-side.
import { formatMoney, type MoneyV2 } from "@shopify/hydrogen";
// `locale` should come from the resolved market. Default only in
// single-market storefronts; market-aware stores must pass the active locale.
export function formatPrice(money: MoneyV2, locale = "en-US"): string {
return formatMoney(money, { locale }).toString();
}
variant.price, variant.compareAtPrice, product.priceRange.minVariantPrice, line.cost.totalAmount, cart.cost.subtotalAmount, etc.en-US in market-aware storefronts.formatPrice() so locale and display options are consistent.withoutTrailingZeros only for presentation choices, never by editing amount strings manually.MoneyV2 values to formatMoney([...]).formatMoney() returns an object that stringifies to the localized price. Use
toString() or template literals for normal UI. Call formatMoney() directly
or add an object-returning wrapper when the design needs split markup:
localizedString - full display string, same as toString().amount - localized numeric portion without currency.numericAmount - parsed number; do not use for cart totals or currency math.currencySymbol, currencyNarrowSymbol, currencyName - currency display variants.parts - Intl.NumberFormatPart[] for custom markup.withoutTrailingZeros, withoutTrailingZerosAndCurrency - presentation-only variants.For ranges, formatMoney([min, max], options) returns an object that stringifies
to the localized range and exposes min, max, and currencyCode. Range
inputs must share one currency.
<p>{formatPrice(selectedVariant?.price ?? product.priceRange.minVariantPrice, locale)}</p>
const range = formatMoney(
[product.priceRange.minVariantPrice, product.priceRange.maxVariantPrice],
{ locale, withoutTrailingZeros: true },
).toString();
"$" + amountNumber(amount).toFixed(2)line.quantity * Number(line.merchandise.price.amount)