Number Convert:
The ComfyNumberConvert node is designed to facilitate seamless conversion between various data types into numeric formats, specifically FLOAT and INT. This node is particularly useful when you need to handle different input types such as integers, floats, strings, and booleans, and convert them into a unified numeric format for further processing or analysis. By providing a single node that manages these conversions, it simplifies workflows and reduces the need for multiple conversion nodes, enhancing efficiency and clarity in your projects. The node ensures that inputs are accurately converted, handling edge cases like empty strings or non-finite numbers with appropriate error messages, thus maintaining data integrity and reliability.
Number Convert Input Parameters:
value
The value parameter is the input that you wish to convert into numeric formats. It accepts multiple types, including integers, floats, strings, and booleans. This flexibility allows you to input data in its original form without needing to pre-process it into a specific type. The node will then handle the conversion internally. There are no explicit minimum, maximum, or default values for this parameter, as it is designed to accept a wide range of inputs. However, it is important to ensure that the input is a valid representation of a number when using strings, as invalid strings will result in conversion errors.
Number Convert Output Parameters:
FLOAT
The FLOAT output parameter provides the converted floating-point representation of the input value. This output is crucial for scenarios where precision is important, such as in calculations involving decimal numbers. The conversion process ensures that the input is accurately represented as a float, even if it originally was an integer or a boolean.
INT
The INT output parameter delivers the integer representation of the input value. This output is particularly useful when you need whole numbers for indexing, counting, or other operations that require integer values. The conversion process truncates any decimal portion of a float input, aligning with typical integer conversion practices.
Number Convert Usage Tips:
- When working with string inputs, ensure that the string is a valid numeric representation to avoid conversion errors. For example, "123" or "45.67" are valid, while "abc" is not.
- Use this node to streamline workflows that require multiple type conversions, reducing the complexity of your node setup and improving readability.
Number Convert Common Errors and Solutions:
Cannot convert empty string to number.
- Explanation: This error occurs when an empty string is provided as input, which cannot be converted into a numeric format.
- Solution: Ensure that the string input is not empty and contains a valid numeric representation before passing it to the node.
Cannot convert string to number: <value>
- Explanation: This error indicates that the provided string cannot be interpreted as a number, possibly due to non-numeric characters.
- Solution: Verify that the string input is a valid number. Remove any non-numeric characters or spaces that might be causing the issue.
Cannot convert non-finite value to number: <float_val>
- Explanation: This error arises when the conversion results in a non-finite number, such as infinity or NaN, which cannot be processed as a valid numeric output.
- Solution: Check the input value to ensure it does not lead to non-finite results. Adjust the input to avoid operations that result in infinity or NaN.
