n8n-io/n8n · error · ExpressionExtensionError

cannot convert to integer

Error message

cannot convert to integer

What it means

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.

Source

Thrown at packages/@n8n/expression-runtime/src/extensions/string-extensions.ts:236

		return decodeURI(value.toString());
	}
	return decodeURIComponent(value.toString());
}

function urlEncode(value: string, extraArgs: boolean[]): string {
	const [entireString = false] = extraArgs;
	if (entireString) {
		return encodeURI(value.toString());
	}
	return encodeURIComponent(value.toString());
}

function toInt(value: string, extraArgs: Array<number | undefined>) {
	const [radix] = extraArgs;
	const int = parseInt(value.replace(CURRENCY_REGEXP, ''), radix);

	if (isNaN(int)) {
		throw new ExpressionExtensionError('cannot convert to integer');
	}

	return int;
}

function toFloat(value: string) {
	if (value.includes(',')) {
		throw new ExpressionExtensionError('cannot convert to float, expected . as decimal separator');
	}

	const float = parseFloat(value.replace(CURRENCY_REGEXP, ''));

	if (isNaN(float)) {
		throw new ExpressionExtensionError('cannot convert to float');
	}

	return float;
}

View on GitHub (pinned to 5ac6606e81)

Solutions

  1. Pre-validate with a regex like `/^-?[\d.,]+$/` or `Number.isFinite(Number(value))` before calling `.toInt()`.
  2. Supply a radix explicitly for non-decimal strings (e.g. `.toInt(16)` for hex).
  3. Default or filter empty/non-numeric rows upstream.

Example fix

// before
{{ $json.code.toInt() }}
// after
{{ $json.code.toInt(16) }}  // code is a hex string
Defensive patterns

Strategy: try-catch

Validate before calling

const s = String($json.code ?? '').trim();
if (!/^-?[\d.,]+$/i.test(s)) {
  throw new Error('toInt(): value has no leading numeric content');
}
return $json;

Type guard

const looksNumeric = (s: string): boolean => /^-?[\d.,]+$/i.test(s.trim());

Try / catch

try {
  return $json.code.toInt();
} catch {
  return null;
}

Prevention

When it happens

Trigger: `.toInt()` on `'abc'`, `''`, `'NaN'`, or any string with no leading numeric content after currency stripping.

Common situations: Field has alphabetic or empty content; value is a label rather than a number; currency regex did not strip a symbol the source used.

Related errors


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/329ac5ecd4e23d09. Report an issue: GitHub.