Change Node: string to number

I hope I don't bore others with my question, it must be simple but I couldn't solve it. In the Change Node I use the code below but the output temp and humi is a string (see image) but that must be a number. Can someone tell me how to adjust the Change Node for that?

{
"datum": payload.datum,
"tijd": payload.tijd,
"temp": payload.uplink_message.decoded_payload.temp_SOIL,
"humi": payload.uplink_message.decoded_payload.water_SOIL,
"conduct": payload.uplink_message.decoded_payload.conduct_SOIL,
"batt": payload.uplink_message.decoded_payload.Bat
}

string

You can use $number() to convert

{
"datum": payload.datum,
"tijd": payload.tijd,
"temp": $number(payload.uplink_message.decoded_payload.temp_SOIL),
"humi": $number(payload.uplink_message.decoded_payload.water_SOIL),
"conduct": payload.uplink_message.decoded_payload.conduct_SOIL,
"batt": payload.uplink_message.decoded_payload.Bat
}

[edit] sorry you are using a change node and Jsonata edited above to reflect that

Thank you very much for your help, this was indeed the solution. I used number but not $number.

Not sure this will help, but here is a nifty function node that I discovered on reddit of all places. Not sure who created it, but it works really well for formatting numbers written as words (strings) to actual numbers.

EDIT: Sorry, first bit of code was a flow. Meant to just sent the function node only.

[{"id":"bc5e2b4a0c8faa25","type":"function","z":"1b42cee9f321f05f","g":"b5294d0d812f30c8","name":"Text2Number","func":"var Small = {\n 'zero': 0,\n 'one': 1,\n 'two': 2,\n 'three': 3,\n 'four': 4,\n 'five': 5,\n 'six': 6,\n 'seven': 7,\n 'eight': 8,\n 'nine': 9,\n 'ten': 10,\n 'eleven': 11,\n 'twelve': 12,\n 'thirteen': 13,\n 'fourteen': 14,\n 'fifteen': 15,\n 'sixteen': 16,\n 'seventeen': 17,\n 'eighteen': 18,\n 'nineteen': 19,\n 'twenty': 20,\n 'thirty': 30,\n 'forty': 40,\n 'fifty': 50,\n 'sixty': 60,\n 'seventy': 70,\n 'eighty': 80,\n 'ninety': 90\n};\n\nvar Magnitude = {\n 'thousand': 1000,\n 'million': 1000000,\n 'billion': 1000000000,\n 'trillion': 1000000000000,\n 'quadrillion': 1000000000000000,\n 'quintillion': 1000000000000000000,\n 'sextillion': 1000000000000000000000,\n 'septillion': 1000000000000000000000000,\n 'octillion': 1000000000000000000000000000,\n 'nonillion': 1000000000000000000000000000000,\n 'decillion': 1000000000000000000000000000000000,\n};\n\nvar a, n, g;\n\n\nmsg.values.number = text2num(msg.values.number);\nreturn msg;\n\n\n\n\n\nfunction text2num(s) {\n a = s.toString().split(/[\\s-]+/);\n n = 0;\n g = 0;\n a.forEach(feach);\n return n + g;\n}\n\nfunction feach(w) {\n var x = Small[w];\n if (x != null) {\n g = g + x;\n }\n else if (w == \"hundred\") {\n g = g * 100;\n }\n else {\n x = Magnitude[w];\n if (x != null) {\n n = n + g * x\n g = 0;\n }\n else { \n alert(\"Unknown number: \"+w); \n }\n }\n}\n\nfunction alert(arg0) {\nthrow new Error(\"Function not implemented.\");\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":540,"wires":[["8a2e0126d074cdf9"]]}]

Thank you!

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