One of the common challenges in building workflows with n8n is handling mismatched data types. Whether you're fetching data from an API, parsing form submissions, or working with spreadsheet entries, you’ll often find that numbers come in as strings. This can break your logic when trying to calculate totals, compare values, or perform arithmetic. If you’ve been wondering how to convert string to number in n8n reliably, this guide will walk you through the best methods—step by step.
Why String-to-Number Conversion Matters in n8n
Data type mismatches can silently cause logic errors in your automation. Imagine this: you're summing values like "100" and "200" thinking they’re numbers. But concatenation instead of arithmetic turns it into "100200".
Conversions become essential in use cases like:
- Summing values from spreadsheets or API responses
- Comparing numeric values for conditions
- Passing numeric types into external APIs
Thankfully, n8n provides intuitive ways to handle these conversions even for no-code users.
Method 1: Using the Set Node to Convert String to Number
The simplest and most straightforward method to convert strings into numbers is by using the Set node with built-in JavaScript expressions.
Step-by-step tutorial
- Add the Set node right after the node where your string variable is coming from (e.g., HTTP Request, Webhook, Google Sheet, etc.).
- In the Set node, enable “Keep Only Set” if needed, or leave it off to retain other data.
- Add a new field:
- Field Name:
convertedNumber - Type:
Number - Value: Click the gears icon → "Add Expression"
- Field Name:
- Inside the expression editor, convert the string:
Number($json["price"])
This small script will take the string value in price and convert it to a proper number under the field convertedNumber.
💡 You can also use
parseFloat()orparseInt()depending on your needs.
Mini Example Use Case
Suppose you’re pulling form entries from a Webhook and the field quantity is "5". You want to multiply that by a unit price.
- Use a Set node to convert:
Number($json["quantity"]) * 10
Now, you get a numeric result: 50 instead of the incorrect "510".
Method 2: Use Code Node for Complex Conversions
If you need to process bulk items or apply logic to arrays, the Code node is a better alternative.
Typical scenario
You fetch a list of product prices as strings and need to calculate the total.
[
{ "price": "100" },
{ "price": "200" },
{ "price": "50" }
]
Code node example
Simply insert a Code node and paste:
return items.map(item => {
return {
json: {
price: Number(item.json.price),
original: item.json.price
}
}
});
This will convert each price string to a number, keeping both versions if needed.
Bonus: You can follow this with an aggregation step using another Code node or Merge node to compute the total.
Method 3: Convert During Data Ingestion
In some cases, it’s ideal to convert data as early as possible—preferably at the ingestion point.
Examples:
- In a Webhook node: Validate and parse incoming query parameters
- In an HTTP Request node: Use expressions to parse numbers before assigning to fields
- In a Google Sheets integration: Set the “valueRenderOption” to show raw values
Although n8n doesn’t auto-convert inputs to numbers, you can use this pre-processing to streamline your flows.
Here’s how you might handle it in a Webhook node + Set node combo:
Number($json["amountReceived"])
This is highly useful in financial workflows or data cleaning setups.
Common Mistakes to Avoid
When converting strings to numbers in n8n, keep an eye out for the following pitfalls:
- Empty strings or null values: These convert to
0orNaN, which may break calculations - Comma-separated digits (
"1,000"): JavaScript can’t parse these by default. Use.replace(",", "")before converting - Currency symbols: Strip these using basic string replacements like
.replace("$", "")
Quick tip: Safe conversion pattern
Number(($json["amount"] || "0").replace(/[^0-9.]/g, ""))
This will convert "$1,234.56" safely into 1234.56.
Bonus: How to Loop and Convert with Arrays
If you pull data from multi-row spreadsheets or APIs, you can convert all values inside a loop using the Item Lists or Code node.
Code node loop example
return items.map(item => ({
json: {
...item.json,
qty: Number(item.json.qty),
total: Number(item.json.qty) * Number(item.json.price)
}
}));
This is especially helpful for eCommerce, invoicing, or lead scoring workflows.
Quick Comparison Table: Conversion Methods
To help you choose the right approach, here’s a simplified comparison:
| Method | Ideal For | Ease of Use |
|---|---|---|
| Set node | Single field conversions | Easy |
| Code node | Arrays or advanced logic | Medium |
| Conversion at input | Direct parsing of incoming webhooks/requests | Easy |
Real-Life Use Cases Where It Matters
- CRM automation: You receive lead scores as strings. You want to trigger workflows if score > 75.
- Finance dashboards: Pull transactions from Airtable or Sheets where amounts come in as strings.
- E-commerce: Multiply quantities and prices to compute order totals.
If you're using tools like Airtable with n8n or handling API data using the HTTP Request node, numeric clarity is key.
Pro Tip: Test with Expressions Panel
Use the expression builder in n8n to actively test the output of your conversion logic. This helps catch subtle issues like undefined, wrong field names, or invalid input types.
FAQ
How do I convert a string to a number in n8n using the Set node?
Use a Set node with an expression like Number($json["fieldName"]). This will parse the string into a number that can be used for calculations and logic gates.
What’s the difference between parseFloat() and Number() in n8n?
Both functions convert strings to numbers, but parseFloat() is more forgiving with partially valid inputs (e.g., it parses "123abc" as 123). Number() is stricter and returns NaN for invalid values.
Can I convert all items in an array at once?
Yes. Use a Code node to map() over the items array and convert each field using Number(item.json.field).
What happens if the conversion fails?
If the input is invalid (like a string with letters), the function returns NaN. Always validate or sanitize inputs before relying on converted values.
Is it possible to handle currency strings like "$1,000.00" in n8n?
Yes. Use a replace method like .replace(/[^0-9.]/g, "") to remove unwanted characters before passing to Number().
String to number conversion in n8n is simple once you understand how expressions and nodes work together. Whether you're building a financial dashboard or managing leads, getting your data typed correctly unlocks more powerful, reliable automation.
Looking to scale your automations further? You might also find our guide on passing data between nodes in n8n or looping through arrays in n8n helpful for complex flows.
Copy-paste templates.
Beginner friendly.