Math Operations

  • Updated

If you’re using Data Entry Fields or Merge Variables to bring data into your decision tree session, you may want to perform math calculations on these variables. Zingtree offers a “Math Webhook” option that lets you assign a new variable to the results of an equation. Here’s how to set it up:

  1. Edit the node where you want the new variable (the result of the math operation) to be calculated.
  2. Click on the Apps/Webhooks section.
  3. Under Webhook to Call, choose Webhook: Zingtree Math.

    2022-04-26_20-39-24.png

     

  4. In the Message Data, you enter the equation. You can insert variables (enclosed with # characters), and assign a result to a new variable (no enclosing # characters). In tthis example from our Zingtree Math Demo tree, we are assigning the variable area to be equal to the variables width times height.
    area=#width#*#height#

 

Example Calculations

Here are some examples:

result=(#a#+#b#)*3

Set variable result to a plus b, times 3.

 

result=round ((#N# * 0.20), 1)

Set variable result to 20 percent of N and round the result to 1 decimal

 

area=round (100 * (#radius#^2)*pi)/100

Set the variable area to pi times the radius squared. Then multiply it by 100, round it to an integer, and divide by 100 to make two decimal places only. (“pi” is a built-in constant).

Reference

These Operations are supported:

Operation Details Example
+ Addition 2+3 = 5
Subtraction 5-3 = 2
* Multiplication 5*3 = 15
/ Division 15/3 = 4
^ Power 5^2 = 25
( ) parenthesis (2 + 3) * 5 = 25

You can also use these Functions

Function Details Example
exp e raised to the power of x exp(1) = 2.718281828
log natural logarithm log(2.718281828) = 1
sqrt square toot sqrt(25) = 5
round round to nearest integer round(3.14) = 3
floor round down floor (3.14) = 3
ceil round up ceil (3.14) = 4
abs absolute value abs(-2) = 2
sgn sign: -1 if < 0, 1 if > 0 sgn(-20) = -1

Trigonometric functions are also available (sin, cos, tan, etc.)

You can also use the constants pi and .

Tip

If you are using single-letter variables, then you don’t need to enclose them with # characters. For example, if w and h are the width and height of a rectangle, you can calculate the area with this equation:

area = w*h

Demo

This tree has an example. You can try it here:

View Demo

 

Was this article helpful?

0 out of 1 found this helpful

Have more questions? Submit a request

Didn't find what you need?

Our friendly customer support team is here to help

Submit a Ticket

Looking for help or advice?

Reach out to our knowledgeable community of users.

Zingtree Community