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^3for 2 cubed)%(Modulo, remainder after division)
- Built-in Functions:
abs\(x\): Absolute value of xacos\(x\): Arc cosine of xasin\(x\): Arc sine of xatan\(x\): Arc tangent of xcbrt\(x\): Cubic root of xceil\(x\): Nearest upper integer (rounds up)cos\(x\): Cosine of xcosh\(x\): Hyperbolic cosine of xexp\(x\): Euler's number (e) raised to the power of xfloor\(x\): Nearest lower integer (rounds down)log\(x\): Natural logarithm of xlog10\(x\): Base-10 logarithm of xlog2\(x\): Base-2 logarithm of xsin\(x\): Sine of xsinh\(x\): Hyperbolic sine of xsqrt\(x\): Square root of xtan\(x\): Tangent of xtanh\(x\): Hyperbolic tangent of xsignum\(x\): Signum function (returns -1, 0, or 1)round\(value, places\): Rounds avalueto a specified number ofplacesafter the decimal point.
- Operators:
-
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
\}
- Formula:
- Result: The action calculates
100 * \(1 - 0.15\)which is85. TheResultwill 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
\}
- Formula:
- Result: The action calculates
\(5.2 * 2.5\) + 10which is13 + 10 = 23. TheResultwill 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
\}
- Formula:
- Result: The action calculates
round\(1000 * \(1 + 0.05\)^3, 2\)which isround\(1000 * 1.157625, 2\)resulting inround\(1157.625, 2\). TheResultwill be "1157.63".