Absolute number in Gravity Forms calculations (2024)

Tutorials » GravityWP BV » Absolute number in Gravity Forms calculations

The Gravity Forms Number field supports basic calculations using values from other fields, like add, subtract, divide and multiply, but sometimes we really miss the possibility to convert a negative value to an absolute number (positive value). For example, when we want to calculate the difference between two values. Can this be solved using out of the box Gravity Forms functionality?

The answer is yes… 😉

But it is rather complex, as you need to add at least 4 extra fields with calculations and conditional logic. It is very easy however if you use our Advanced Number Field addon. Here you can just tick the ‘Force Absolute’ box, among some other great advanced number field features:

Absolute number in Gravity Forms calculations (1)

Still want to do it the hard way? Buckle up and we will walk you through it step by step.

How to calculate an absolute value in a Gravity Form

We achieve this using a combination of multiple number field, calculations and conditional logic. We will explain it with an example form where the user inputs his (or her) height in meters. Then the form calculates the difference in centimeters. We want this value to be a positive number in any case. We will build a form where you can input your own height in meters. The form then will calculate the absolute difference in centimeters of your height compared to the average woman height, using only Gravity Forms core functionality.

Step by step instruction

Open the form editor to create a new or edit an existing form. Add the following number fields:

  1. The first number field has a fixed value, which is the more or less average height of a woman in meters. We enable calculations and fill in 1.60.
Absolute number in Gravity Forms calculations (2)
  1. The second number field is a user input.
Absolute number in Gravity Forms calculations (3)
  1. In the third number field we calculate the difference like Average minus the user input. When your height is above 1.60 meter the result will be a negative value. As we don’t want the user to see this field we hide it in the field visibility settings.
Absolute number in Gravity Forms calculations (4)
  1. In the fourth field (hidden) we calculate the difference the other way around. When your height is above 1.60 meter the result will be a positive value. Now we have two fields which calculate the different. Now at least one of these contains a positive value. But how to determine which one? We need two more fields for this.
Absolute number in Gravity Forms calculations (5)
  1. Therefore we add another hidden number field, which copies the value of the ‘Average minus input’-field. But we also enable conditional logic for this field and show it only in case ‘Average minus input’ has a value greater than 0.
Absolute number in Gravity Forms calculations (6)
  1. And we add yet another hidden number field which copies the value of ‘Input minus average’ which also shows conditionally but now when ‘Input minus average’ has a value greater than 0. Because of this conditional logic the ‘Difference1’ and ‘Difference2’ field will never show at the same time. Note that ‘show’ is not the same as ‘visible’, the field is still invisible to the user as it is hidden in the field settings. In this case ‘show’ means the fields conditional logic evaluates to true and therefore the form will be able to use its value.
Absolute number in Gravity Forms calculations (7)
  1. In the last number field we add we will finally be able to calculate the difference as an absolute number. We do this by adding up Difference1 and Difference2. Only one of this fields is shown due to conditional logic. The other one will hold a value of 0, because it is hidden by the conditional logic. Finally we multiply it by 100 to convert centimeters to meters.
Absolute number in Gravity Forms calculations (8)

As you can see this is quite a lot of work te get an absolute number value in Gravity Forms, and you need quite a lot of fields to achieve this.

Demo form calculating the absolute number

You can try it out here. Click the button to show the fields hidden by the visibility setting. Note Difference1 and Difference2 being shown conditionally.

Our Premium Add-ons for Gravity Forms

List DatepickerAdd a Datepicker with calendar select to a column or multiple columns in a Gravity Forms List Field.
Update Multiple EntriesTrigger the update of multiple entries in a target form by submitting an entry in a trigger form.
List DropdownAdd a Dropdown Select with choices to a column or multiple columns in a Gravity Forms List Field.
JWT PrefillCreate JSON Webtokens to populate fields in your Gravity Form. With a secure key you can validate the data you don’t want to be tampered with.
List Number FormatWith this Gravity Forms Add-on you can change List Field columns into a number field, do calculations within a row or column. Extra merge tags are available with total counts of columns.
Advanced Merge TagsThis Gravity Forms Add-On adds extra Merge Tag modifiers (and a lot of power). From the most common used functions like capitalize and length to changing date formats.

Read more tutorials about GravityWP BV

GravityWP develops add-ons to collect and manage your data better.

Show all calculations Gravity FormsDo you need an overview of all the calculations in your Gravity Form? With our Merge Tags Add-on you can easily get a list of all calculations (formulas) in one form.
Pay per word with starting price for Gravity FormsWith the gwp_word_count merge tag modifier for Gravity Forms it is possible to use the word count value of a text field in a formula. This way you can create a flexible Pay per Word calculation based on the amount of words in a text field.
Substring Modifier for Gravity Forms Merge TagsDo you want to return a portion of a Merge Tag string output? And specify an offset and length of the part of the Merge Tag output? With Advanced Merge Tags it's as easy as it gets.
Quick overview of Gravity Forms Conditional Logic rulesWhen you're working with a lot of Conditional Logic rules in your form it can be a challenge to keep an overview. Our Merge Tags Add-on for Gravity Forms has a Conditional Logic Tab which creates a quick overview of all the rules in your form.
Bulk Update Gravity FormsEntriesDo you want to bulk update a large batch of Gravity Forms Entries? Like 12321 entries? A nearly undoable task by hand, but a breeze with our Update Multiple Entries add-on.

All tutorials GravityWP BV

Absolute number in Gravity Forms calculations (2024)
Top Articles
Latest Posts
Article information

Author: Virgilio Hermann JD

Last Updated:

Views: 5572

Rating: 4 / 5 (61 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Virgilio Hermann JD

Birthday: 1997-12-21

Address: 6946 Schoen Cove, Sipesshire, MO 55944

Phone: +3763365785260

Job: Accounting Engineer

Hobby: Web surfing, Rafting, Dowsing, Stand-up comedy, Ghost hunting, Swimming, Amateur radio

Introduction: My name is Virgilio Hermann JD, I am a fine, gifted, beautiful, encouraging, kind, talented, zealous person who loves writing and wants to share my knowledge and understanding with you.