Display a number field without thousand separator [RESOLVED]

Hi,

I’m using Gravity Forms in order to display a calculator / simulator.

The form contains two or three Number fields to field.
At the bottom, I have one Number field with calculation enabled.

Here is a screenshot : Screenshot by Lightshot

I would like to hide the thousands separator (a comma).

I found something in the documentation here : gform_include_thousands_sep_pre_format_number - Gravity Forms

I created the following snippet :

add_filter( 'gform_include_thousands_sep_pre_format_number' , '__return_false' );

But it seems not working.
Any idea please ?

The gform_include_thousands_sep_pre_format_number filter doesn’t apply to the live form, it only applies when the entry value is formatted for display on the list and detail pages, or when merge tags output the values in confirmations and notifications.

To change the formatting of a calculation result on the front-end, you’ll need to use the JavaScript-based gform_calculation_format_result filter:

1 Like

Thank you for your answer.

I tried this, but it doesn’t work …

<script>
gform.addFilter('gform_calculation_format_result', function(formattedResult, result, formulaField, formId, calcObj) {
        // Retirer le séparateur de milliers (virgule ou point)
        formattedResult = formattedResult.replace(/[,\.]/g, '');
        return formattedResult;
    });
</script>

Hi,

I’m not a developer and I still need help on this.
Please could you help me again ?

Hi there,

Could you please let me know how or where you’ve tried the provided JavaScript code which wasn’t working? Is it possible to share the live form URL so I can further investigate to resolve it?

Hi,

Here is the live form URL : Approvisionnement restaurant optimisé via contrôle d'accès

I used the WPCode Lite plugin to insert the code.

Thanks.

First, get the field ID from the edit form page, like the screenshot below.

Then, try the following code.

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;
});

The output will look like the following screen recording. :point_down:

Preview

Give it a try, and let me know how that goes! :smile:

It appears that your field ID is the same as mine, so it’s 4 and you can use my provided code without modification. Here is the preview: :point_down:

It works, thank you very much ! :pray:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.