Home > widget-integration > FilterFormatHelper > formatMoney
FilterFormatHelper.formatMoney() method
Formats money value according to specified format options.
This is the core formatting method that applies Shopify money format templates (e.g., "${{amount}}", "{{amount}} USD") to numeric values. It handles various format types including amount, amount_no_decimals, amount_with_comma_separator, etc. Override this method to customize the fundamental money formatting logic.
Signature:
formatMoney(money: number | string, format?: string, withTrailingZeros?: boolean, showCentAsSuperscript?: boolean, removePriceDecimal?: boolean, removeDecimalPoint?: boolean): string;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
money |
number | string |
Money value in cents (e.g., 1999 for $19.99) or string representation |
|
format |
string |
(Optional) Shopify format template string (e.g., "${{amount}}"). Defaults to shop's money_format. |
|
withTrailingZeros |
boolean |
(Optional) If false, removes .00 or ,00 from end of formatted string |
|
showCentAsSuperscript |
boolean |
(Optional) If true, displays decimal portion as superscript HTML |
|
removePriceDecimal |
boolean |
(Optional) If true, removes entire decimal portion (e.g., $19.99 → $19) |
|
removeDecimalPoint |
boolean |
(Optional) If true, removes decimal point when using superscript cents |
Returns:
string
Formatted money string with specified options applied
Example 1
Basic usage:
const formatted = helper.formatMoney(1999, '${{amount}}');
// Returns: "$19.99"
Example 2
Extend to add custom format types:
window.boostWidgetIntegration.extend('FilterFormatHelper', (FilterFormatHelper) => {
return class CustomFilterFormatHelper extends FilterFormatHelper {
formatMoney(money, format, withTrailingZeros, showCentAsSuperscript, removePriceDecimal, removeDecimalPoint) {
// Add support for custom "rounded" format
if (format === 'money_rounded') {
format = '${{amount_no_decimals}}';
}
return super.formatMoney(money, format, withTrailingZeros, showCentAsSuperscript, removePriceDecimal, removeDecimalPoint);
}
};
});