Formula
Function: Formula
This action allows you to perform mathematical calculations using a custom formula and a set of variables. It's perfect for automating calculations like sales tax, discounts, area, or any other numerical operation your application needs, without writing any code.
Input
- Formula
- A text string representing the mathematical expression you want to calculate. You can include placeholders for variables within this formula, like
\{\{myVariable\}\}. - Supported Operators: Addition (
+), Subtraction (-), Multiplication (*), Division (/), Exponentiation (^), Modulo (%). - Supported Functions: Absolute value (
abs), Arc cosine (acos), Arc sine (asin), Arc tangent (atan), Cubic root (cbrt), Nearest upper integer (ceil), Cosine (cos), Hyperbolic cosine (cosh), Euler's number raised to the power (exp), Nearest lower integer (floor), Natural logarithm (log), Base-10 logarithm (log10), Base-2 logarithm (log2), Sine (sin), Hyperbolic sine (sinh), Square root (sqrt), Tangent (tan), Hyperbolic tangent (tanh), Signum function (signum).
- A text string representing the mathematical expression you want to calculate. You can include placeholders for variables within this formula, like
- Variables
- An object containing the values for the placeholders used in your "Formula". Each key in this object should match a placeholder name (without the
\{\{\}\}), and its value will be substituted into the formula before calculation. For example, if your formula is\{\{price\}\} * \{\{quantity\}\}, your variables object would havepriceandquantityas attributes.
- An object containing the values for the placeholders used in your "Formula". Each key in this object should match a placeholder name (without the
Output
- Result
- The calculated numerical value derived from your formula and variables.
Execution Flow
Real-Life Examples
Here are some practical ways you can use the "Formula" action in your applications:
Example 1: Calculate Total Order Price with Tax
Imagine you're building an e-commerce application and need to calculate the final price of an order including sales tax.
- Inputs:
- Formula:
\(\{\{item_price\}\} * \{\{quantity\}\}\) * \(1 + \{\{tax_rate\}\} / 100\) - Variables:
item_price:50quantity:2tax_rate:8
- Formula:
- Result:
108(The total price of two items at $50 each, with an 8% tax, is $108).
Example 2: Determine the Hypotenuse of a Right Triangle
For an application that helps users with geometry, you might need to calculate the length of the hypotenuse given two sides of a right triangle.
- Inputs:
- Formula:
sqrt\(\{\{side_a\}\} ^ 2 + \{\{side_b\}\} ^ 2\) - Variables:
side_a:3side_b:4
- Formula:
- Result:
5(The hypotenuse of a right triangle with sides 3 and 4 is 5).
Example 3: Calculate a Discounted Price
If you're running a promotion and need to apply a percentage discount to a product price.
- Inputs:
- Formula:
\{\{original_price\}\} * \(1 - \{\{discount_percentage\}\} / 100\) - Variables:
original_price:200discount_percentage:15
- Formula:
- Result:
170(A product originally priced at $200 with a 15% discount will cost $170).