{"record":{"id":"329ac5ecd4e23d09","repo":"n8n-io/n8n","slug":"cannot-convert-to-integer","errorCode":null,"errorMessage":"cannot convert to integer","messagePattern":"cannot convert to integer","errorType":"exception","errorClass":"ExpressionExtensionError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/expression-runtime/src/extensions/string-extensions.ts","lineNumber":236,"sourceCode":"\t\treturn decodeURI(value.toString());\n\t}\n\treturn decodeURIComponent(value.toString());\n}\n\nfunction urlEncode(value: string, extraArgs: boolean[]): string {\n\tconst [entireString = false] = extraArgs;\n\tif (entireString) {\n\t\treturn encodeURI(value.toString());\n\t}\n\treturn encodeURIComponent(value.toString());\n}\n\nfunction toInt(value: string, extraArgs: Array<number | undefined>) {\n\tconst [radix] = extraArgs;\n\tconst int = parseInt(value.replace(CURRENCY_REGEXP, ''), radix);\n\n\tif (isNaN(int)) {\n\t\tthrow new ExpressionExtensionError('cannot convert to integer');\n\t}\n\n\treturn int;\n}\n\nfunction toFloat(value: string) {\n\tif (value.includes(',')) {\n\t\tthrow new ExpressionExtensionError('cannot convert to float, expected . as decimal separator');\n\t}\n\n\tconst float = parseFloat(value.replace(CURRENCY_REGEXP, ''));\n\n\tif (isNaN(float)) {\n\t\tthrow new ExpressionExtensionError('cannot convert to float');\n\t}\n\n\treturn float;\n}","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/expression-runtime/src/extensions/string-extensions.ts#L218-L254","documentation":"String `.toInt(radix?)` strips currency symbols via `CURRENCY_REGEXP`, then `parseInt(..., radix)`. If the result is `NaN` it throws 'cannot convert to integer'. A radix may be supplied as the optional second argument.","triggerScenarios":"`.toInt()` on `'abc'`, `''`, `'NaN'`, or any string with no leading numeric content after currency stripping.","commonSituations":"Field has alphabetic or empty content; value is a label rather than a number; currency regex did not strip a symbol the source used.","solutions":["Pre-validate with a regex like `/^-?[\\d.,]+$/` or `Number.isFinite(Number(value))` before calling `.toInt()`.","Supply a radix explicitly for non-decimal strings (e.g. `.toInt(16)` for hex).","Default or filter empty/non-numeric rows upstream."],"exampleFix":"// before\n{{ $json.code.toInt() }}\n// after\n{{ $json.code.toInt(16) }}  // code is a hex string","handlingStrategy":"try-catch","validationCode":"const s = String($json.code ?? '').trim();\nif (!/^-?[\\d.,]+$/i.test(s)) {\n  throw new Error('toInt(): value has no leading numeric content');\n}\nreturn $json;","typeGuard":"const looksNumeric = (s: string): boolean => /^-?[\\d.,]+$/i.test(s.trim());","tryCatchPattern":"try {\n  return $json.code.toInt();\n} catch {\n  return null;\n}","preventionTips":["Pre-validate numeric content with a regex in a Code node.","Supply a radix for non-decimal strings (`.toInt(16)`).","Filter or default empty / non-numeric rows upstream."],"tags":["expression","string","number","parsing","data-quality"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}