Skip to main content

formatMoney

formatMoney formats a monetary value based on your shop's currency settings. It's the JavaScript counterpart to Liquid's money filters and is essential whenever you're rendering prices client-side (variant switching, cart totals, etc.), since Shopify's AJAX API returns prices as an integer number of cents.

It accepts:

ArgumentTypeDefaultDescription
centsnumber \| stringThe value in cents, e.g. 300 for £3.00.
formatstringwindow.theme.moneyFormatThe shop's money_format string. Defaults to the value on the global theme object.
note

By default formatMoney reads the format from window.theme.moneyFormat, so make sure that has been set (it's populated by the starter theme). You can always pass an explicit format string as the second argument.

Usage examples

Basic

// Assuming window.theme.moneyFormat === '£{{ amount }}'
window.BAO.utils.formatMoney(300) // '£3.00'
window.BAO.utils.formatMoney(1999) // '£19.99'

Passing an explicit format

window.BAO.utils.formatMoney(250000, '${{ amount_with_comma_separator }}')
// '$2.500,00'