How to change "." by "," in a numeric value before submitting to google sheets

How to change “.” by “,” in a numeric value

Hello how are you? I hope you’re well. I have a problem when replacing “.” by “,” inside my workflow. I’d like to change this to it’s a numeric value, and it’s normally coming like this:

Example:
“charge_amount”: “93.23”

But I would like it to come like this:

Example:
“charge_amount”: “93,23”

Do you know how I could resolve this?

Note: The values change, they are not always the same, so I can’t use an “if” node or a “Switch”

The workflow

Output returned by the last node

[
  {
    "Order Id": "tGPPfKx",
    "Status": "refused",
    "Product": "Example product",
    "Customer Name": "John Doe",
    "Customer Email": "[email protected]",
    "Customer CPF": "78987310423",
    "Customer Phone": "+15788173529",
    "Installments": 1,
    "Type": "producer",
    "Pagamento": "mastercard",
    "Refuse Reason": "possible_fraud_ip",
    "Tracking src": null,
    "Tracking sck": null,
    "Tracking utm_source": null,
    "Tracking utm_medium": null,
    "Tracking utm_campaign": null,
    "Tracking utm_content": null,
    "Tracking utm_term": null,
    "Creation Date": "2022-07-25 08:55",
    "Updated At": "2022-07-25 08:55",
    "yourcommisionamount": 82.97,
    "kiwifyfee": 10.26,
    "productbaseprice": 93.23,
    "Your Commision Amount": "",
    "Kiwify Fee": "",
    "Product Base Price": ""
  }
]

Hi @Linecker, welcome to the community :tada:

I couldn’t find a charge_amount value in your example data and your examples look identical to me:

Example:
“charge_amount”: “93.23”

But I would like it to come like this:

Example:
“charge_amount”: “93.23”

If you need the different format only in your Google Sheet you might want to let Google handle the conversion by setting the right number format in your column. Then in n8n you can set the Value Input Mode to User Entered (it’s RAW by default) and Google should handle the conversion for you:

image

Thank you very much, and I’m glad to be here.

I would like to say that before registering here I always read your posts and I admire you very much. And I’m extremely honored to see you now responding to my first comment on the community.

And, I amended the post, I had done it wrong. Sorry, I would like to replace the webhook data. To replace “.” per “,”

Yes, values usually come with a “.” as default. But I want to change that “.” by comma before reaching google sheets.

2 Likes

So if you’d like to change it before reaching Google Sheets you might want to use a Set node to do so.

In this context it’s important to understand that in Javascript (which is used by n8n) numbers are represented with a period . as a decimal separator. So to get rid of the period, we’ll need to convert your existing number into a string. The .toLocaleString() method can help with this.

Here’s a quick example converting the productbaseprice value from your example using the de-DE locale (using a comma , rather than a period) in a Set node with an expression of {{ $json["productbaseprice"].toLocaleString('de-DE') }}:

This logic can be used everywhere in n8n and Google Sheet will also keep this formatting in RAW mode:

image

Hope this helps!

2 Likes

My friend, thank you very much. This will help me a lot.

1 Like

You are most welcome! Give me a shout if you run into any trouble with this :slight_smile: