Convert a String to a Number in n8n
A form sends quantity as text, so '2' + 1 becomes '21'. Convert it before doing math.
Incoming Payload / Data:
{
"quantity": "12"
}
βοΈ Your expression is executed against test data β any correct solution passes. +10 XP
β Solution & explanation
Output: 12
parseInt() reads a whole number; Number() converts the whole string (including decimals) and returns NaN if it isn't numeric.π‘ Pro tip: For prices with decimals use parseFloat($json.price) or Number() β parseInt drops the decimals.
Also accepted: Number($json.quantity), parseInt($json.quantity, 10)
π parseInt() / Number() reference: syntax & more examples →