☰
Documentation

gwp_calculate

The gwp_calculate Merge Tag returns the result of a calculation formula and formats the number as specified.

Options

formula (required)The arithmetic expression to be calculated. Use field merge tags, e.g., {Number:5}, within the formula.
number_format (optional, default = ‘decimal_dot’)Specifies the format of the number. You can use decimal_comma, decimal_dot, or currency.
thousands_sep (optional, default = true)Determines whether to include a thousands separator.
Set to false to disable.
This option will be ignored for the currency format.
raw (optional, default = false)Output the number in decimal dot notation without any formatting. When true the other formatting options will be ignored.
currency (optional)Currency code for number_format=currency, like EUR or USD. Default is the currency set in Forms → Settings.
decimals (optional)Integer value to set the number of decimals to round to. Without decimals the result is not rounded.
round (optional)Set rounding options: round (default), ceil (always up) or floor (always down). Only used together with decimals.

Where it works

gwp_calculate calculates with the values of an entry, so it works in notifications, confirmations, GravityView, Gravity Flow and other places that run after submission. Without an entry, for example in a field’s default value, it returns nothing (or an error, depending on the plugin settings).

The formula can contain field merge tags with advanced modifiers. They are replaced before the calculation, so make sure they return a number:

{gwp_calculate formula="{Text:1:gwp_word_count} * 0.10" number_format=currency}
{gwp_calculate formula="{Order ID:1:gwp_sum_matched_entries_values form_id=4 match_id=2 return_id=5 raw=true} * 1.21" decimals=2}

Use raw=true on gwp_sum_matched_entries_values inside a formula, so the sum has no thousands separators.

Examples

{gwp_calculate formula="({Number:5}+{Number2:7})*{Number3:6}"}

Returns the calculated result based on the provided formula using decimal point formatting.


{gwp_calculate formula="({Number:5}+{Number2:7})*{Number3:6}" number_format=decimal_comma thousands_sep=false}

Returns the calculated result with decimal comma formatting, but without thousands separator.


{gwp_calculate formula="({Number:5}+{Number2:7})*{Number3:6}" number_format=currency}

Returns the calculated result formatted as currency. The thousands separator will be included according to the Gravity Forms currency settings.


{gwp_calculate formula="({Number:5}+{Number2:7})*{Number3:6}" raw=true}

Returns the calculated result in decimal dot notation without any formatting.


{gwp_calculate formula="{Price:4} / 3" decimals=2 round=ceil number_format=currency currency=EUR}

Rounds the result up to 2 decimals and formats it as euros.


{gwp_calculate formula="1234.5678 * 2" decimals=2 round=floor number_format=decimal_comma}

Returns 2.469,13: rounded down to 2 decimals, with a decimal comma and a dot as thousands separator.

Frequently Asked Questions

What does the gwp_calculate merge tag do?

The gwp_calculate merge tag lets you perform math calculations using field values in your Gravity Forms. You can create a formula using merge tags from your form fields, and the result will be displayed wherever you use this merge tag. You can also choose how the result looks by adjusting the format, rounding, and decimal settings. Example: {gwp_calculate formula="({Number 1:3} + {Number 2:5}) * {Number 3:6}"}

How do I reference field values inside the formula?

You can reference any field by using its regular merge tag inside the formula=”…” part of gwp_calculate. Example: {gwp_calculate formula="{Amount:4} + {Tax:8}"} This will add the values entered in the Amount and Tax fields.

What number formats can I use?

You can choose how the result should look by setting the number_format option: -decimal_dot → Example: 1234.56 -decimal_comma → Example: 1.234,56 -currency → Example: $1,234.56 (based on your Gravity Forms currency settings) Example: {gwp_calculate formula="{Price:4} * 1.2" number_format=currency}

How can I control rounding and decimals?

You can fine-tune the result with: -decimals=X → number of decimal places to show -round=round → round normally (default) -round=ceil → always round up -round=floor → always round down Example: {gwp_calculate formula="{Score:7} / 3" decimals=2 round=round} This will round the result to 2 decimal places.

Can I include multiple fields in the formula?

Yes! You can include as many fields as you like by using their merge tags inside the formula. You can also use parentheses to control the order of operations, just like in regular math. Example: {gwp_calculate formula="({Field 1:1} + {Field 2:2}) * {Field 3:3}"}

Options Where it works Examples Frequently Asked Questions
Proudly powered by WordPress