Converting a number to a string

Hi!

Can you tell me how I can convert a number to a string and back?
I take data from two sources, they are the same, but the type of value is different, so the equivalence check does not work.

Hey @a1ekseev!

Welcome to the n8n community! :slightly_smiling_face:

You can convert a number to a string using the .toString() method. And to convert the string back to number you can use the parseInt() method.

In the workflow below, I am converting the number to a string, inside the Expression Editor. {{$node["Set"].json["value_number"].toString()}}. This only converts the number to string for checking the values, and the original data type remains the same.

{
  "nodes": [
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "number": [
            {
              "name": "value_number",
              "value": 17
            }
          ],
          "string": [
            {
              "name": "value_string",
              "value": "17"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"Set\"].json[\"value_number\"].toString()}}",
              "value2": "={{$node[\"Set\"].json[\"value_string\"]}}"
            }
          ],
          "number": []
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    }
  ],
  "connections": {
    "Set": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

I hope this helps. :slightly_smiling_face:

2 Likes

Now I understand the syntax.
Thank you!

Happy that I could help. :slightly_smiling_face:

Have fun!