Ask AI
Skip to main content

Formula

Function: Formula​

This action helps you perform mathematical calculations using a formula you define, along with specific values for any variables within that formula. It's like having a powerful calculator built right into your application, allowing you to automate complex computations without writing any code.

Input​

  • Formula (STRING, Required) The mathematical expression you want to calculate. This can include numbers, operators, and placeholders for your variables.

    • Operators:
      • + (Addition)
      • - (Subtraction)
      • * (Multiplication)
      • / (Division)
      • ^ (Exponentiation, e.g., 2^3 for 2 cubed)
      • % (Modulo, remainder after division)
    • Built-in Functions:
      • abs\(x\): Absolute value of x
      • acos\(x\): Arc cosine of x
      • asin\(x\): Arc sine of x
      • atan\(x\): Arc tangent of x
      • cbrt\(x\): Cubic root of x
      • ceil\(x\): Nearest upper integer (rounds up)
      • cos\(x\): Cosine of x
      • cosh\(x\): Hyperbolic cosine of x
      • exp\(x\): Euler's number (e) raised to the power of x
      • floor\(x\): Nearest lower integer (rounds down)
      • log\(x\): Natural logarithm of x
      • log10\(x\): Base-10 logarithm of x
      • log2\(x\): Base-2 logarithm of x
      • sin\(x\): Sine of x
      • sinh\(x\): Hyperbolic sine of x
      • sqrt\(x\): Square root of x
      • tan\(x\): Tangent of x
      • tanh\(x\): Hyperbolic tangent of x
      • signum\(x\): Signum function (returns -1, 0, or 1)
      • round\(value, places\): Rounds a value to a specified number of places after the decimal point.
  • Variables (OBJECT, Required) A collection of key-value pairs where each key is the name of a placeholder in your Formula (e.g., \{\{PRICE\}\}) and its corresponding value is the number you want to use for that placeholder in the calculation.

Output​

  • Result (STRING) The final calculated value of the formula, presented as text.

Execution Flow​

Real-Life Examples​

Here are some practical ways you can use the Formula action in your applications:

Example 1: Calculating a Simple Discounted Price​

Imagine you want to calculate the final price of an item after applying a discount.

  • Inputs:
    • Formula: \{\{ORIGINAL_PRICE\}\} * \(1 - \{\{DISCOUNT_PERCENTAGE\}\}\)
    • Variables:
      \{
      "ORIGINAL_PRICE": 100,
      "DISCOUNT_PERCENTAGE": 0.15
      \}
  • Result: The action calculates 100 * \(1 - 0.15\) which is 85. The Result will be "85".

Example 2: Determining Shipping Cost Based on Weight and Distance​

Let's say your shipping cost is calculated by multiplying the item's weight by a base rate and then adding a distance surcharge.

  • Inputs:
    • Formula: \(\{\{WEIGHT\}\} * 2.5\) + \{\{DISTANCE_SURCHARGE\}\}
    • Variables:
      \{
      "WEIGHT": 5.2,
      "DISTANCE_SURCHARGE": 10
      \}
  • Result: The action calculates \(5.2 * 2.5\) + 10 which is 13 + 10 = 23. The Result will be "23".

Example 3: Calculating Compound Interest and Rounding to Two Decimal Places​

You need to calculate the future value of an investment with compound interest and ensure the result is rounded to two decimal places for currency display.

  • Inputs:
    • Formula: round\(\{\{PRINCIPAL\}\} * \(1 + \{\{RATE\}\}\)^\{\{YEARS\}\}, 2\)
    • Variables:
      \{
      "PRINCIPAL": 1000,
      "RATE": 0.05,
      "YEARS": 3
      \}
  • Result: The action calculates round\(1000 * \(1 + 0.05\)^3, 2\) which is round\(1000 * 1.157625, 2\) resulting in round\(1157.625, 2\). The Result will be "1157.63".