Dividetwonumbers
Purpose
This node is designed to perform division between two numeric values. It takes in two numbers as inputs, checks for validity, and safely computes their quotient. The results can then be used in further computations or data analytics processes within the Vantage platform.
Settings
Input Settings
-
Setting Name:
input1- Input Type: Numeric (can be a string or number)
- Description: This is the first value to be divided. If not provided in the inputs, it defaults to the value specified in the configuration or falls back to
1. Changing this setting alters the value that will be divided by the second input. - Default Value:
1
-
Setting Name:
input2- Input Type: Numeric (can be a string or number)
- Description: This is the second value used as the divisor. If not provided in the inputs, it defaults to the value specified in the configuration or falls back to
1. Adjusting this value will change the divisor, affecting the outcome of the division. Furthermore, it is critical to ensure this value is not0, as division by zero is mathematically undefined. - Default Value:
1
Error Handling
The function includes basic validations:
- If either
input1orinput2is not a valid number (using the node), an error will be thrown, alerting the user that both inputs must be numeric. - If
input2is0, another error will be thrown stating that division by zero is not allowed. These validations ensure robust error handling and user awareness.
How It Works
- Upon invocation, the function retrieves the values of
input1andinput2, prioritizing provided inputs over configuration defaults. - Both values are converted to numbers to ensure that valid numeric operations can be performed.
- The function then checks for:
- Numeric validity of the inputs.
- Division by zero condition.
- If both checks pass, the division operation is executed, and the result is returned as an output in a structured format.
Expected Data
The function expects the following data structure for inputs:
json
{
"inputs": {
"input1": <number or string>,
"input2": <number or string>
},
"config": {
"input1": <number or string>,
"input2": <number or string>
}
}- Both
input1andinput2can be numbers or string representations of numbers. If either is not numeric after conversion, an error will occur.
Use Cases & Examples
Use Cases
- Financial Analysis: A company can use this logic to calculate profit margins by dividing profit by total revenue to assess efficiency.
- Data Normalization: In a dataset, certain values may need to be normalized against a base value, which can be handled through division.
- Dynamic Reporting: A reporting tool can leverage this logic to create real-time analytics dashboards that display ratios, such as conversion rates (sales divided by leads).
Example Configuration
Use Case: Calculate profit margin from sales data.
Configuration Data:
json
{
"inputs": {
"input1": "15000", // Profit
"input2": "50000" // Total Revenue
},
"config": {}
}Expected Output: The function would process this input and return:
json
{
"output1": 0.3 // The profit margin rate of 30%
}In this example, the profit of $15,000 is divided by total revenue of $50,000 to yield a profit margin of 30%. This insight can be crucial for stakeholders analyzing business performance.