Math Connector


Math Connector

The Math Connector provides basic arithmetic operations for numerical calculations.


Operations


add

Adds two numbers together.

Parameters

ParameterTypeRequiredDefaultDescription
xnumberYes-The first operand
ynumberYes-The second operand

Examples

// Add two integers
{ "x": 5, "y": 3 }

// Output
{ "result": 8 }
// Add decimal numbers
{ "x": 10.5, "y": 4.25 }

// Output
{ "result": 14.75 }
// Add negative numbers
"data": { "x": -5, "y": 10 }

// Output
{ "result": 5 }

subtract

Subtracts the second number from the first.

Parameters

ParameterTypeRequiredDefaultDescription
xnumberYes-The first operand
ynumberYes-The second operand

Examples

// Subtract two integers
{ "x": 10, "y": 3 }

// Output
{ "result": 7 }
// Result is negative
{ "x": 5, "y": 10 }

// Output
{ "result": -5 }
// Subtract decimal numbers
{ "x": 20.5, "y": 5.25 }

// Output
{ "result": 15.25 }

multiply

Multiplies two numbers together.

Parameters

ParameterTypeRequiredDefaultDescription
xnumberYes-The first operand
ynumberYes-The second operand

Examples

// Multiply two integers
{ "x": 6, "y": 7 }

// Output
{ "result": 42 }
// Multiply by zero
{ "x": 100, "y": 0 }

// Output
{ "result": 0 }
// Multiply decimal numbers
{ "x": 2.5, "y": 4 }

// Output
{ "result": 10 }
// Multiply negative numbers
{ "x": -3, "y": -4 }

// Output
{ "result": 12 }

divide

Divides the first number by the second.

Parameters

ParameterTypeRequiredDefaultDescription
xnumberYes-The dividend
ynumberYes-The divisor

Examples

// Divide two integers
{ "x": 20, "y": 4 }

// Output
{ "result": 5 }
// Division with decimal result
{ "x": 10, "y": 4 }

// Output
{ "result": 2.5 }
// Divide decimal numbers
{ "x": 7.5, "y": 2.5 }

// Output
{ "result": 3 }

Error Handling

Attempting to divide by zero will throw an error:

// Divide by zero (throws error)
{ "x": 10, "y": 0 }

// Error
{ "error": "Divide by zero" }

Type Conversion

The Math Connector automatically converts string inputs to numbers. This allows seamless integration with context variables that may be stored as strings.

// String inputs are converted to numbers
{ "x": "5", "y": "3" }

// Output
{ "result": 8 }

Note: If the input cannot be converted to a valid number, the result will be NaN (Not a Number).


Using with Context Variables

Math operations can use context variables for dynamic calculations:

{
    "x": "{{context.parameters.subtotal}}",
    "y": "{{context.parameters.tax}}"
}