gform_calculation_format_result

Description

The “gform_calculation_format_result” filter can be used to override the default formatting for a calculated result.

Usage

The gform_calculation_result filter is a JavaScript filter.

gform.addFilter( 'gform_calculation_format_result', function( result, formulaField, formId, calcObj ) {
  // do stuff
  return result;
} );

Parameters

Examples

Format the number field with id 1 as currency.

<script>
    gform.addFilter( 'gform_calculation_format_result', function(formattedResult, result, formulaField, formId, calcObj ){    
        if ( formulaField.field_id == '1' ){ // Change 1 to your field id number
          formattedResult = gformFormatNumber(result, !gformIsNumber(formulaField.rounding) ? -1 : formulaField.rounding, ',', '');
        }
        var currency = new Currency(gf_global.gf_currency_config);
        return currency.toMoney(formattedResult);
    });
</script>

Show always two decimals.

<script>
gform.addFilter('gform_calculation_format_result', function (formattedResult, result, formulaField, formId, calcObj) {
    if (formulaField.field_id == '3') { // Change 3 to your field id number
        var decimalSeparator = ',',
            thousandSeparator = '.',
            currency = new Currency(gf_global.gf_currency_config);
 
        formattedResult = currency.numberFormat(result, 2, decimalSeparator, thousandSeparator);
    }
    return formattedResult;
});
</script>

Placement

Your code snippet can be placed in an HTML field on your form or in a theme custom JavaScript file.

See also the JavaScript/jQuery section in this article: Where Do I Put This Code?

Source Code

This filter is located in js/gravityforms.js.