To String
Converts a numeric value to its string representation. This is essential for displaying numbers in UI elements, concatenating with text, formatting output, or preparing data for systems that expect string input.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If ContinueOnError property is true, no error is caught when the project is executed even if Catch node is used.
Input
- Number - The numeric value to convert to a string. Default variable name is
numfrom Message scope. Can be a constant, variable, or JavaScript expression.
Options
- Number Type - Specifies the output format:
- Double - Preserves decimal places (e.g.,
123.456becomes"123.456000") - Integer - Converts to whole number, truncating decimals (e.g.,
123.456becomes"123")
- Double - Preserves decimal places (e.g.,
Output
- String - The string representation of the number. Default variable name is
strin Message scope.
Examples
Example 1: Convert Integer to String
Convert a count or ID to string format:
// Input Number
42
// Options
Number Type: Integer
Output: "42"
Example 2: Convert Decimal to String
Convert a price or measurement to string:
// Input Number
19.99
// Options
Number Type: Double
Output: "19.990000"
Example 3: Format for Display
Prepare a number for concatenation in a message:
// Input Number
${flow.itemCount}
// Options
Number Type: Integer
Then use in a template:
"You have " + str + " items in your cart"
Output: "You have 5 items in your cart"
Example 4: Convert Calculation Result
Convert the result of a calculation to string:
// Input Number (JavaScript expression)
${msg.price * msg.quantity}
// Options
Number Type: Double
Output: String representation of the total, e.g., "149.970000"
Example 5: Truncate Decimals
Convert a decimal to whole number string:
// Input Number
123.789
// Options
Number Type: Integer
Output: "123" (decimals are truncated, not rounded)
Tips for Effective Use
-
Choose the Right Type:
- Use Integer for counts, IDs, or whole numbers
- Use Double for prices, measurements, or scientific values
- Note: Integer truncates (doesn't round) decimal values
-
Formatting Decimals:
- The Double format adds trailing zeros (e.g.,
"123.450000") - For custom formatting, use JavaScript instead:
${msg.num.toFixed(2)} // Always 2 decimals: "123.45"
${msg.num.toString()} // Minimal format: "123.45"
- The Double format adds trailing zeros (e.g.,
-
String Concatenation:
- After conversion, use the string in templates or concatenation
- Example:
"Order #" + str - Or use JavaScript template literals:
`Order #${str}`
-
API Integration:
- Some APIs require numeric values as strings
- Use this node to convert before sending to API
- Particularly common in form submissions or query parameters
-
Type Safety:
- Convert numbers to strings when working with nodes that expect string input
- Prevents type coercion issues in downstream operations
Common Use Cases
- Display Numbers: Convert numeric values for UI display or messages
- Text Concatenation: Combine numbers with text strings
- API Requests: Format numbers as strings for API parameters
- File Names: Create file names with numeric components
- Logging: Convert numbers for log messages or reports
- Form Filling: Prepare numeric data for text input fields
- CSV/Text Files: Format numbers for text-based file formats
Common Errors and Solutions
Error: "Input is not a number"
Cause: The input value is not a valid number.
Solution: Ensure the input is numeric or use JavaScript to convert:
// Wrong
${msg.value} // where value is "not a number"
// Correct
${parseFloat(msg.value) || 0}
Unexpected Trailing Zeros with Double Type
Cause: The Double format uses Go's %f format specifier, which adds trailing zeros.
Solution: Use JavaScript for custom formatting:
// Instead of using To String node with Double type
// Use JavaScript expression in a later node:
${parseFloat(msg.str)} // Removes trailing zeros
${msg.num.toFixed(2)} // Custom decimal places
Integer Truncation Instead of Rounding
Cause: The Integer type truncates decimals (e.g., 3.9 becomes "3", not "4").
Solution: If you need rounding, use JavaScript before conversion:
// Input Number (round first)
${Math.round(msg.num)}
// Options
Number Type: Integer
Or use JavaScript directly:
${Math.round(msg.num).toString()}
Lost Precision with Large Numbers
Cause: JavaScript numbers have precision limits (53 bits for integers).
Solution: For very large numbers (> 2^53), consider:
- Using string representation from the source
- Breaking into smaller components
- Using specialized libraries for big number arithmetic
Advanced Examples
Custom Number Formatting
For more control over formatting, use JavaScript:
// Currency formatting (2 decimals)
${msg.price.toFixed(2)} // "19.99"
// Thousands separator
${msg.amount.toLocaleString()} // "1,234,567"
// Scientific notation
${msg.largeNumber.toExponential(2)} // "1.23e+6"
// Padding with zeros
${msg.id.toString().padStart(6, '0')} // "000042"
Conditional Formatting
// Format based on value size
${msg.num >= 1000000
? (msg.num / 1000000).toFixed(1) + 'M'
: msg.num >= 1000
? (msg.num / 1000).toFixed(1) + 'K'
: msg.num.toString()
}
// Examples: "1.5M", "250.3K", "42"
Percentage Formatting
// Convert decimal to percentage string
${(msg.ratio * 100).toFixed(1) + '%'}
// Example: 0.756 becomes "75.6%"
Comparison with JavaScript toString()
While you can use JavaScript's toString() method directly in expressions, the To String node provides:
- Visual Clarity: Explicit conversion step visible in flow diagram
- Integer Truncation: Built-in option for removing decimals
- Error Handling: Consistent error handling through node properties
- No Code Required: Non-technical users can configure without JavaScript knowledge
However, for custom formatting needs, JavaScript expressions offer more flexibility.