Gravity Forms disables number formatting for the calculated results

·

·

Gravity Forms allows for the modification of calculated results using the gform_calculation_format_result hook, which can be found here: https://docs.gravityforms.com/gform_calculation_format_result/. The documentation includes two examples.

To disable the formatting of the calculated result, first obtain the field ID from the form editing page, as shown in the screenshot below.

Now, use the provided code and replace the field ID with the ID of your form field, if it is different. You can use this code in your child theme JavaScript file or utilize the Simple Custom CSS and JS plugin.

gform.addFilter('gform_calculation_format_result', function (formattedResult, result, formulaField, formId, calcObj) {
    if (formulaField.field_id == '4') { // field ID
        formattedResult = result.toFixed(0);
    }

    return formattedResult;
});

Now, if you check the output, you will see that the formatting has been disabled and the output is a plain number.

Disabled calculated result

I hope that helps. Let me know if you’re having any issues disabling the formatting.


Meet the author

Faisal Ahammad

I’m working as Support Engineer at Saturday Drive Inc (AKA Ninja Forms) and General Translation Editor (GTE) for the #bn_BD 🇧🇩 language. As an active contributor to WordPress and open-source projects, I have translated over 60 themes, plugins, and WordPress core. I also have a small YouTube channel where I share my knowledge.


Leave a Reply

Your email address will not be published. Required fields are marked *