Hello how to division msg.payload value /10

hello
I would like to inquire about a script issue in Function Block.
I've never done a script before...
The value of msg.payload is 203.
I want to divide by 20.3.
Please advise.

Please help.
Thank you so much for your interest.

You are receiving an array with a single element in the msg.payload

You could test this code:

let test = msg.payload[0]/10;
node.warn(test);

vary vary thank you

I'm leaving a message because I want to ask a question again.
How do I change the array value to /10?
Thanks for your reply.

Try this in a function node...

let test = msg.payload[0]/10;
msg.payload = test;
return msg;

Not sure from your question whether you want to divide the first element of the array by 10 and pass that SINGLE value on in a new 'msg.payload' to the next part of your flow OR replace the first element in the array and pass the WHOLE of the original array on?

If you want to do the latter, try this...

msg.payload[0] = msg.payload[0]/10;
return msg;


온도 = temp

thank you very very much ~.~!!!!!

using change node

[{"id":"88097a8bc88ab7c2","type":"inject","z":"f0ae706f0b39513f","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"203","payloadType":"num","x":450,"y":570,"wires":[["1caf47266b526982"]]},{"id":"1caf47266b526982","type":"change","z":"f0ae706f0b39513f","name":"Divide input value by 10","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload/10","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":570,"wires":[["699141205d222fd0"]]},{"id":"699141205d222fd0","type":"debug","z":"f0ae706f0b39513f","name":"debug 438","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":910,"y":570,"wires":[]}]

thank you very very much

thank you very very much

1 Like

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