The Equations feature in Mango lets you extract even more insight from your data by performing basic mathematical functions using numerical attribute variables, or a mixture of numeric attributes variables and fixed values.

You can insert an equation in to the custom popup editor to add value to your map user’s experience, configure an interactive calculator popup, or include an equation in a query report.

In a Custom Popup, an equation can provide additional insights to the underlying attribute data.

## Constructing an equation

The operator must be wrapped in hashed curly brackets: `#{ equation }#`

, and each value in the equation should be wrapped in single quotes `'`

or double quotes `"`

to escape any content that might invalidate the statement.

Equations can perform elementary arithmetic operations:

+ (addition)

− (subtraction)

÷ (division)

× (multiplication)

For example, you have a census tract data containing three numeric attribute fields: `{total_population}`

, `workforce`

, and `employed`

, and you want to report the unemployment rate for queried or selected tracts. As this is a simple percentage equation, we can approach the equation in the same way we might perform an equation in Excel: foo / bar * 100

Percentage of total population in the workforce:

#{ ( '{workforce}' / '{total population}' ) * '100' }#

Percentage of people in the workforce who are employed:

#{ ( '{employed}' / '{workforce}' ) * '100' }#

Percentage of people in the workforce who are unemployed:

#{ '100' - ( '{employed}' / '{workforce}' ) * '100' }#

Equations can also perform conditional arguments and format both equation output, as well as modify the display formatting of any numeric attribute.

## Formatting output

### Thousand separators

By default, equation outputs will be a raw, unformatted value. To add the default language formatting for the user's device, use the following format:

#{ ('{numeric_attribute}').toLocaleString() }#

Add a $ in front of the equation, and you'll have a currency formatted number.

$#{ ('{numeric_attribute}').toLocaleString() }#

Customise the number format with language sensitive digit and decimal separators by in. For example, French:

#{ ({'numeric_attribute}').toLocaleString('fr-FR') }#

This will also work with basic equations, just wrap the equation in the first set of parenthesis:

#{ ('{attribute_x}' * '{attribute_y}').toLocaleString() }#

#{ ( ('{attribute_x}' * '{attribute_y}') / '{attribute_z}' ).toLocaleString() }#

Learn more about LocaleString formatting.

### Decimals

In this example, we take the totals of two variables `males`

and `totalpop`

and perform a basic equation to reveal the percentage:

#{ ( '{males}' / '{totpop}' ) * '100' }#%

= 53.5257974219999965725946822%

Note that by default, the full length of the decimals in the result will be displayed. To control decimal places, you can:

Round the calculation's output using the Math.round() method:

#{ Math.round( ( {males} / {totpop} ) * '100' ) }#%

= 54%

Specify the number of decimal places you require using the .toFixed() method:

#{ (( '{males}' / '{totpop}' ) * '100' ).toFixed(0) }#%

= 54%

#{ (( '{males}' / '{totpop}' ) * '100' ).toFixed(2) }#%

= 53.54%

#{ (( '{males}' / '{totpop}' ) * '100' ).toFixed(8) }#%

= 53.52579742%

## Javascript Math function reference

Math.abs(a)

the absolute value of a

Math.acos(a)

arc cosine of a

Math.asin(a)

arc sine of a

Math.atan(a)

arc tangent of a

Math.atan2(a,b)

arc tangent of a/b

Math.ceil(a)

integer closest to a and not less than a

Math.cos(a)

cosine of a

Math.exp(a)

exponent of a (Math.E to the power a)

Math.floor(a)

integer closest to a, not greater than a

Math.log(a)

log of a base e

Math.max(a,b)

the maximum of a and b

Math.min(a,b)

the minimum of a and b

Math.pow(a,b)

a to the power b

Math.random()

pseudorandom number 0 to 1

Math.round(a)

integer closest to a

Math.sin(a)

sine of a

Math.sqrt(a)

square root of a

Math.tan(a)

tangent of a