Multiplytwonumbers
Overview
The node is designed to perform multiplication on two numerical inputs. It takes either direct inputs or configuration settings, processes these inputs, and returns their product. This functionality is essential for applications requiring mathematical operations, such as financial calculations, statistical analyses, and problem-solving scenarios involving quantitative data.
Settings
The node includes various settings that can be configured to influence its operation. Below is a detailed breakdown of each setting:
1. inputs
- Input Type: Object
- What it Does: This setting allows passing two input values,
input1andinput2. These values are used for the multiplication operation. If both inputs are not provided, the function will resort to the default values defined in theconfigobject. - Default Value: An empty object (
{}).
2. input1
- Input Type: Numeric
- What it Does: Represents the first number to be multiplied. If the user provides this value through inputs, it will override any value set in the configuration. The function converts this input to a number for processing.
- Default Value:
0(if not provided).
3. input2
- Input Type: Numeric
- What it Does: Represents the second number to be multiplied. Similar to
input1, if a value is provided through inputs, it will take precedence over the configuration. Likeinput1, this input is converted to a number. - Default Value:
0(if not provided).
Error Handling
- The function includes a validation process that checks if both
input1andinput2are valid numbers. If either of the inputs fails this validation (e.g., they are non-numeric), the function will throw an error with a descriptive message:MultiplyTwoNumbers: Both inputs must be valid numbers.
How It Works
- Input Gathering: The function retrieves values for
input1andinput2either from theinputsobject or from theconfigobject. - Parsing to Numbers: Both values are converted to numbers using
Number()to ensure they are in a suitable format for multiplication. - Validation: It checks if either of the converted values is not a number using
isNaN(). If either value fails this check, it throws an error. - Multiplication: If both inputs are valid numbers, it computes the product of
input1andinput2. - Return Value: Finally, the function returns an object containing the result of the multiplication in the
output1key.
Data Expectations
The node expects two numerical inputs, which can either be provided directly through an object when invoking the function or via configuration parameters. Inputs must be of numeric type or convertible to numbers. If the inputs are invalid, an error is thrown, making proper validation essential for the function's successful execution.
Example of Valid Data:
{
"inputs": {
"input1": 5,
"input2": 10
},
"config": {}
}Use Cases & Examples
Use Cases
- Financial Applications: Utilize this node to calculate total costs by multiplying unit prices with quantities sold.
- Statistical Data Validations: Validate numerical data inputs by ensuring they can be multiplied to derive products in analytical applications.
- Mathematical Simulations: Implement this logic in mathematical software that requires various calculations, such as educational platforms for teaching multiplication concepts.
Detailed Example
Use Case: Calculating Total Sales from Unit Price and Quantity Sold.
Configuration Data: Suppose a business needs to determine the total income from selling 40 units of a product priced at $25 each.
Example Configuration:
{
"inputs": {
"input1": 25,
"input2": 40
},
"config": {}
}Expected Output: When the node is executed with the above configuration, the output will be:
{
"output1": 1000
}This indicates that the total sales amount is $1000 (25 multiplied by 40).