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
{ "operation": "add", "data": { "x": 5, "y": 3 } }

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

// Output
{ "result": 14.75 }
// Add negative numbers
{ "operation": "add", "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
{ "operation": "subtract", "data": { "x": 10, "y": 3 } }

// Output
# Math Connector

The Math Connector provides basic arithmetic operations for numerical calculations.

---

## Operations

---

### `add`

Adds two numbers together.

#### Parameters

| Parameter | Type   | Required | Default | Description          |
|-----------|--------|----------|---------|----------------------|
| `x`       | number | Yes      | -       | The first operand    |
| `y`       | number | Yes      | -       | The second operand   |

#### Examples

```json
// Add two integers
{ "operation": "add", "data": { "x": 5, "y": 3 } }

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

// Output
{ "result": 14.75 }
// Add negative numbers
{ "operation": "add", "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
{ "operation": "subtract", "data": { "x": 10, "y": 3 } }

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

// Output
{ "result": -5 }
// Subtract decimal numbers
{ "operation": "subtract", "data": { "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
{ "operation": "multiply", "data": { "x": 6, "y": 7 } }

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

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

// Output
{ "result": 10 }
// Multiply negative numbers
{ "operation": "multiply", "data": { "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
{ "operation": "divide", "data": { "x": 20, "y": 4 } }

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

// Output
{ "result": 2.5 }
// Divide decimal numbers
{ "operation": "divide", "data": { "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)
{ "operation": "divide", "data": { "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 template variables that may be stored as strings.

// String inputs are converted to numbers
{ "operation": "add", "data": { "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 template variables

Math operations can use template variables for dynamic calculations:

{
  "operation": "add",
  "data": {
    "x": "{{ params.subtotal }}",
    "y": "{{ params.tax }}"
  }
}
{
  "operation": "multiply",
  "data": {
    "x": "{{params.price}}",
    "y": "{{params.quantity}}"
  }
}
{
  "operation": "divide",
  "data": {
    "x": "{{params.total}}",
    "y": "{{params.numberOfItems}}"
  }
}