Gravity Forms disables number formatting for the calculated results

·

·

disables number formatting

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 a former Support Engineer at Saturday Drive Inc. (AKA Ninja Forms) and a GTE for the #bn_BD language. As an active contributor to WordPress, I have contributed to over 60 themes, plugins, and the WordPress core. I also run a small YouTube channel where I share my knowledge.

Leave a Reply

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

More from the blog


Recommended Topics


Popular Tags

documents formidable forms free stuff gravity forms malaysia ninja forms oop open source php wordpress