Mathematical Calculations

🕒 Estimated Reading Time: 1 Minute

In this article

Overview

To make your bot smarter, Elegant Bots allows Mathematical Calculations to be done and save to a Custom Field. 

You cannot only do the basic calculations like addition, subtraction, multiplication, or division but also complex mathematical and scientific calculations like the functions are mentioned below.

We’ll show you how it can be done with an example. 

Follow the steps to know how to make calculations inside your chatbot.

Step 1. Create (or Edit) the Flow you want to include calculation operations on.

Step 2. Click the + Sign to Select Options, then click ‘Action’. 

Step 3. Once you have the Action Block, Open it, Click on ‘Add Content’>Actions then choose Set Custom Field.

Once done Selecting ‘Set Custom Field’ Action & Opening it, you will see a Wizard like the image below. 

Let’s do a simple illustration, a basic Addition within the bot. 

We will need 3 Custom Fields and for the purposes of this illustration, we will use ‘ValueofA’, ValueofB, and ‘Amount’ as our custom fields with ‘Number’ as Data Type. Let’s begin… 

Example: Basic Addition 

4. Open a starting step as show in the image below. It has 2 ‘Get User Data’ Content, The First Field asks for the ‘Value of A’ with the CUF ‘ValueofA’ and the Second Field asks for the ‘Value of B’ with the CUF ‘ValueofB’. 

Step 5. Open a ‘Set Custom Field’ Action and configure as follows: 

Custom Field: ‘Amount’, Operation: ‘Use Custom Formula’, and Value: {{ValueofA}} + {{ValueofB}}.

Please refer to the image below. 

Step 6. Create a step to display the result of the operation which will have this values {{ValueofA}} + {{ValueofB}} = {{Amount}}. 

The flow will look like the image below. The Math Operation happening in the Custom Field ‘Amount’ is simple, Save the {{ValueofA}} + {{ValueofB}} to {{Amount}}.

Step 7: Save, and ‘Run’ it. It will show like the image below. 

Here are some basic math examples that you can do inside the Elegant Bots platform:

  • 1+2*3-4
  • 1 + 2 * 3 – 4
  • pi * 2
  • PI * 2
  • abs(1) + min(1,2) * max(1,2,3)
  • min(1+2, abs(-1))
  • 1 + ((2 – 3) * (5 – 7))
  • 2 * (-3)

Here is the example of formats with syntax:

  • 1         // A term can consist of just a number
  • (1+((2))) // Usage of obsolete brackets is allowed
  • 00001     // Prefixing a number with obsolete zero digits is possible
  • .1        // Omitting a zero digit before a period character is okay

Here are some awesome list to provide more value for this article:

Operators:

  • Addition (+)
  • Subtraction (-)
  • Multiplication (*) 
  • Division (/)

Functions:

  • abs
  • aCos
  • aCosH
  • aSin
  • aSinH
  • aTan
  • aTanH
  • aTanTwo
  • ceil
  • cos
  • cosH
  • degToRad
  • en
  • exp
  • expMOne
  • floor
  • fMod
  • hypot
  • log
  • logOneP
  • logTen
  • max
  • min
  • pow
  • radToDeg
  • round
  • sin
  • sinH
  • sqrt
  • tan
  • tanH

Constants:

  • e
  • euler
  • lnPi
  • lnTen
  • lnTwo
  • logTenE
  • logTwoE
  • onePi
  • pi
  • piFour
  • piTwo
  • sqrtOneTwo
  • sqrtPi
  • sqrtThree
  • sqrtTwo
  • twoPi
  • twoSqrtPi

Others:

( (right-faced brackets)

) (left-faced brackets)

, (comma)

. (dot)

That’s it! Enjoy…