Hi, I currently have a msg.payload that is a number, for example 51.571372, which is a latitude from a GNSS device (GPS and Glonass etc), which jumps around a lot, being to 6 decimal places, the last of which is less than a meter I think.
I thought I’d use Node Red Contrib Calc to reduce the number of decimal places but instead of one number I think it wants an array: eg.
51.571372, 3
Where 3 is just how many decimal places I want. In the setup of the node is a selector of how many decimal places to output. I’m tempted to just select average and 3 in the setup node, but is there a simple way to turn a number into an array of numbers? Maybe a change node where I set msg.payload to the value of msg.payload, 3? Or a template? There must be a simple way to do this I have not found.
Not sure what you mean by an array of numbers but you can round it to 3 decimal places with Jsonata in a change node:
Thanks. I only meant array as in the standard programming way. I have installed that node instead of a calculator node.
maynot be simple, but this should give what you are expecting.
[{"id":"44d8a26c4d7f3def","type":"inject","z":"4cde86148e5b95f7","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":380,"y":1950,"wires":[["966059502bae2ddf"]]},{"id":"bd0d75b2b7019e7f","type":"inject","z":"4cde86148e5b95f7","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"3","payloadType":"num","x":425,"y":2025,"wires":[["966059502bae2ddf"]]},{"id":"966059502bae2ddf","type":"join","z":"4cde86148e5b95f7","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":625,"y":2000,"wires":[["1284b4c3cd741f8c"]]},{"id":"1284b4c3cd741f8c","type":"debug","z":"4cde86148e5b95f7","name":"debug 2670","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":780,"y":2000,"wires":[]}]