subtractTwoNumbers Documentation
Overview
The node is a component of the Vantage analytics and data platform that performs a subtraction operation on two numerical inputs. It is designed to take two numeric values and return their difference, facilitating numerical calculations and data processing in various analytical scenarios.
Purpose
The primary purpose of the node is to allow users to easily compute the difference between two numbers. It ensures that the inputs are valid and handles errors gracefully, making it a reliable utility for any calculations requiring subtraction.
Settings
The node has the following configurable settings:
1. input1
- Input Type: Numeric / String
- Description: This setting represents the first number from which the second number will be subtracted. It accepts both numerical and string representations of numbers.
- Effect of Changing the Setting: Modifying this setting will directly affect the value of the first operand in the subtraction operation. If
input1is set to a different numeric value, the output will change accordingly. - Default Value:
0(If neitherinputs.input1norconfig.input1are provided, the default is used.)
2. input2
- Input Type: Numeric / String
- Description: This setting represents the second number that will be subtracted from the first. Similar to
input1, it can be a numeric or string value. - Effect of Changing the Setting: Changing this setting alters the second operand in the subtraction, thus affecting the result of the operation. If
input2is altered, the difference produced will vary. - Default Value:
0(If neitherinputs.input2norconfig.input2are specified, this default is utilized.)
Function Behavior
- The function first retrieves the values of
input1andinput2from provided inputs or configuration, defaulting to0as needed. - It converts both values to numbers and checks for validity. If either value is not a number, an error is thrown.
- It calculates the difference between
input1andinput2and returns it asoutput1.
Data Expectations
The node expects the following data format for its operation:
- Inputs: The function expects an object with keys
input1andinput2, which can be either numeric values or strings that represent numbers. - Output: The function returns an object containing the key
output1, which holds the numeric result of the subtraction.
Example of expected input format:
{
"inputs": {
"input1": "10",
"input2": "5"
}
}Error Handling
If either input1 or input2 is not a valid number, the function will throw an error:
SubtractTwoNumbers: Both inputs must be valid numbers.
This validation ensures that the operation does not proceed with invalid data, maintaining the integrity of the results.
Use Cases & Examples
Use Cases
- Financial Calculation: A financial analyst needs to calculate the net profit by subtracting total expenses from total revenue for each transaction.
- Data Transformation: In data preprocessing, a data engineer may need to adjust time duration by subtracting two time values for analysis.
- Inventory Management: A product manager wants to assess stock changes by subtracting sold items from the total inventory count.
Example Configuration
Use Case: Calculating Net Profit
In this scenario, an organization wants to determine net profit by subtracting total expenses from total revenue. The values may be obtained from a dataset and passed to the node.
Sample Configuration Data:
{
"inputs": {
"input1": "15000", // Total Revenue
"input2": "5000" // Total Expenses
}
}Expected Output:
The expected output after executing the node with the above input data would be:
{
"output1": 10000 // Net Profit
}This configuration efficiently calculates the net profit, which is vital for financial reporting and analytics. Each adjustment of input1 or input2 would allow for dynamic updates to net profit calculations as new data becomes available.