n8n LabBeginner
Round Decimal Numbers in n8n using JavaScript Math
An invoice calculation returned a long decimal number. Round it to 2 decimal places.
Live Execution Simulator
Idle
π₯
Incoming Data
βοΈ
n8n Node
π―
Next Step
> Ready. Type your expression below and click "Check Answer" to run the node.
Incoming Payload / Data:
{
"amount": 49.9982
}
$json.amount.
βοΈ Your expression is executed against test data β any correct solution passes. +10 XP
β Solution & explanation
$json.amount.toFixed(2)
Output: "50.00"
toFixed(2) rounds a number to 2 decimal places. Note that it returns a string, which is ideal for displaying prices but not for further math.π‘ Pro tip: To keep a number type, use Math.round($json.amount * 100) / 100 or n8n's built-in $json.amount.round(2).