Simple math without js

Looking at:

How could i multiply the number 20 by 2?
Simply 20 * 2 doesn’t work returns the string (i guess) 20 * 2.
There’s an earlier demand for a calculation node but i can’t find it (yet?):
https://github.com/n8n-io/n8n/issues/18

In reality i’m facing the following issue; i receive a quantity and price from a source, but need to calculate line total to be able to hand it over to the target.

Probably easy in Function Item, but i don’t know how to refer to results in earlier nodes there and would like to prevent to need to learn javascript (that’s why i use n8n :slight_smile: )

Thank you in advance for any helpful tips :slight_smile:

Welcome to the community @Arjan_den_Ouden

If you provide an example of the input and the desired output, I can help you with the function node.

Hi Ricardo,
Tnx for your reply, the input is the example in this n8n website:
https://n8n.io/workflows/526
i would like to change the output of 20 to be multiplied by, let’s say 2, so 40 is the desired outcome.
When i do 20 * 2 in the formula editor this is parsed as a string as the outcome then is 20 * 2 and not 40. So is would like to perform basis math somewhere.

The example below should do it.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        -1910,
        40
      ]
    },
    {
      "parameters": {
        "values": {
          "number": [
            {
              "name": "number",
              "value": 20
            }
          ],
          "string": [
            {
              "name": "string",
              "value": "From n8n with love"
            }
          ],
          "boolean": [
            {
              "name": "boolean",
              "value": true
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "position": [
        -1620,
        40
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "values": {
          "number": [
            {
              "name": "number",
              "value": "={{$node[\"Set\"].json[\"number\"] * 2}}"
            }
          ],
          "string": [
            {
              "name": "string",
              "value": "From n8n with love"
            }
          ],
          "boolean": [
            {
              "name": "boolean",
              "value": true
            }
          ]
        },
        "options": {}
      },
      "name": "Set1",
      "type": "n8n-nodes-base.set",
      "position": [
        -1380,
        40
      ],
      "typeVersion": 1
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "Set1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Ah ok, i see now, thank you so much!

1 Like

Of course. Let us know if you have more questions.

1 Like