Unicode to number


I am having some issues to convert what appears to be unicode into number. I am running a python script from a exec module where the msg.payload returns a value which seems to be unicode(?)

Adding a change node returns an error.

Any idea how this could be solved with very limited knowledge related to programming..


Changenode looks like this:


It isn't a unicode issue, you simply have a trailing newline (\n). Apply trim to the string before conversion.

Trimming input strings is nearly always the best approach anyway.

Hi, is that applied in the change node or a seperate node?

You can do it in your JSONata. Something like (untested): $number($trim(payload)) I think.

Julian is correct that you would need to get rid of the trailing newline character -- but the embedded comma is still going to cause the conversion to fail...

If you know that the payload will only contain a formatted number string, you could use:
$replace(payload, /\D/, "").$number()

This strips out all of the non-digit characters (including newlines) and then tries to convert the remaining digits to a number.

But in general, it would be best to modify the python code to return a valid number (unformatted) without any whitespace or line breaks...

Ah, your eyesight (or monitor) is obviously better than mine as I completely missed that!

I guess that could be a locale issue though since many European languages swap what we would call "normal" - e.g. "2,163,000.45" becomes "2.163.000,45"

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.