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:
- Edit the node where you want the new variable (the result of the math operation) to be calculated.
- Click on the Apps/Webhooks section.
- Under Webhook to Call, choose Webhook: Zingtree Math.
- 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.
Here are some examples:
Set variable result to a plus b, times 3.
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).
These Operations are supported:
|+||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
|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 e .
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
This tree has an example. You can try it here: