# Gravity Forms Add-on: MIN/MAX Calculations

## Background Case Study

Gravity Forms is a great tool for collecting information from your visitors. Doing even semi-sophisticated logic or math beyond basic arithmetic can get complex and cluttered in a hurry. We ran into this shortfall with a client and were disappointed when the quickest solution turned out to be resorting to a template hack. Usually when we hand a client a tool like a form builder it's so they can be empowered to manage things in-house and don't always have to hire us to make subsequent changes.

The number fields in Gravity Forms have
support for some calculations but it's literally just the basics: addition, subtraction, multiplication
and division. For this client's needs, if we'd had some way of integrating an
`IF/ELSE`

statement within the equation (like a
ternary operator) or some kind of function that could return the greater or lesser of two values we could've
avoided a lot of headaches.

## The Plugin

After that experience we looked into extending the built-in calculation features. From that this plugin was born!
**Gravity Forms Add-on: MIN/MAX Calculations** is a simple add-on that does what it's called: it allows
us to use
`MIN()`

and
`MAX()`

functions within the formula fields:

## Examples & Demos

This will return the smaller of the two fields (inserted as merge tags) and divide 2:

`MIN({Field:1}, {Field:2}) / 2`

And this will return the larger of the two fields and proceed to multiply by 4:

`MAX({Field:1}, {Field:2}) * 4`

You could even write something like this to always ensure a larger value is divided by a smaller value:

`MAX({Field:1}, {Field:2}) / MIN({Field:1}, {Field:2})`

This will return either the value of a field (if greater than zero) or zero:

`MAX({Field:1}, 0)`

This will return either the value of a field (if less than zero) or zero:

`MIN({Field:1}, 0)`

## Download & Use

We hope you find this plugin as useful as we did. It should be available in the WordPress Plugin Directory soon!

In the meantime there are instructions for how to install and use this plugin in the GitHub repository or you can always hire us to help you.