Skip to main content

To Number

Converts a string to a numeric value (float64).

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.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • String - String to convert to a number. Supports integers, decimals, negative numbers, and scientific notation.

Options

This node does not have configurable options.

Output

  • Result - The converted numeric value as a float64.

How It Works

The To Number node parses string representations of numbers and converts them to float64 values:

Supported formats:

  • Integers: "42", "-17", "0"
  • Decimals: "3.14", "-0.5", "99.99"
  • Scientific notation: "1.23e10", "5e-3"
  • Leading/trailing spaces are not automatically trimmed

The conversion uses Go's strconv.ParseFloat with 64-bit precision.

Usage Examples

Example 1: Convert Integer String

  • String: "42"
  • Result: 42.0

Example 2: Convert Decimal String

  • String: "3.14159"
  • Result: 3.14159

Example 3: Convert Negative Number

  • String: "-99.5"
  • Result: -99.5

Example 4: Scientific Notation

  • String: "1.5e3"
  • Result: 1500.0

Example 5: From User Input

  • String: ${msg.userInput} // "123.45"
  • Result: 123.45

Error Handling

The node will return an error in the following cases:

Empty String:

String: ""
Error: "String value cannot be empty"

Invalid Number Format:

String: "abc"
Error: strconv.ParseFloat: parsing "abc": invalid syntax

Invalid Characters:

String: "12.34.56"
Error: strconv.ParseFloat: parsing "12.34.56": invalid syntax

Tips

  • Use Trim node first to remove leading/trailing whitespace
  • The result is always a float64, even for whole numbers
  • For currency values, consider precision limitations of floating-point
  • Supports scientific notation for very large or small numbers
  • Use for processing numerical data from CSV files, forms, or APIs
  • Combine with mathematical operations after conversion

Common Errors and Solutions

Error: "String value cannot be empty"

  • Cause: Empty string provided
  • Solution: Validate that the string contains a value before conversion

Error: Invalid syntax parsing error

  • Cause: String contains non-numeric characters
  • Solution: Clean the string first - remove currency symbols, commas, spaces, etc.

Error: Incorrect decimal separator

  • Cause: Some locales use comma instead of period for decimals
  • Solution: Use Replace node to convert commas to periods: "1,234.56" → "1234.56"

Practical RPA Examples

Example: Process CSV Data

Input String: "1234.56"
Output: 1234.56
Use Case: Convert price strings from CSV to numbers for calculations

Example: Clean and Convert Currency

Step 1: Replace "$" with "" → "123.45"
Step 2: ToNumber → 123.45
Use Case: Process currency values from web scraping

Example: Calculate Sum

Input String: "50.75"
Output: 50.75
Next: Add to running total
Use Case: Sum invoice amounts

Example: API Response Processing

Input String: ${msg.response.count}  // "152"
Output: 152.0
Use Case: Convert string numbers from JSON to actual numbers

Example: Form Validation

Input String: ${msg.quantity}
If conversion succeeds: Valid number
If conversion fails: Show error to user
Use Case: Validate numeric input from forms
  • ToBoolean - Convert string to boolean
  • ToString - Convert any value to string
  • Replace - Clean string before conversion
  • Trim - Remove whitespace before conversion