Replace Number

I´m trying to replace “.” to “,” in a number.

[
{
“cart”: 30707 ,
“basicAmount”: 14.5 ,
“Id”: “b57”
}
]

Is this possible, i use replace function but it only replace string.

How can i change from 14.5 to 14,5?

Welcome to the community @lsoldado !

Numbers do neither have dots nor commas. It is simply how the browser/n8n displays it. So it is impossible to replace them in an actual number.

What you can do, is to convert the number to a string (text) and then replace it there. The expression would look like this:

{{$json.basicAmount.toString().replace('.', ',')}}

But be aware that as soon as it is a string, you can not use it for any calculations anymore.

Here an example workflow:

{
  "nodes": [
    {
      "parameters": {
        "values": {
          "number": [
            {
              "name": "basicAmount",
              "value": 14.5
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "basicAmount",
              "value": "={{$json.basicAmount.toString().replace('.', ',')}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    }
  ],
  "connections": {
    "Set": {
      "main": [
        [
          {
            "node": "Set1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Thanks @jan, it works :slight_smile:

Glad to hear! Have fun!