Paywave_$ appears with a lot of decimal places that I need to reduce to one. However as this value is being sent to a csv file and not to a dashboard display I cannot use the Value format.
How can I change this in the function. I have tried .tofixed(1) but this creates problems and |number:1 does not seem to work.
Thanks in advance
var originalNumber = 5.78945612301
var formatedString = originalNumber.toFixed(1) // 5.7 (string)
var formatedNumber = parseFloat(formatedString) // 5.7 (number)
// can be combined
var formatedNumber = parseFloat(originalNumber.toFixed(1))
// or if original is not needed anymore apply it directly to original
originalNumber = parseFloat(originalNumber.toFixed(1))
Hi this is my first application so am doing a bit of learning here...so thanks for the help..
below is what I see in the debug - I believe it is a number
Hi ukmoose,
Paywave_ is a variable coming from a device that has several other variables. Paywave_ is producing the payload of 2.299999952316284 in the first instance.
I need to reduce this down to 2.3
Have you added the Debug node after the Function node you mention at the start of your first post? In which case you are showing us what comes out of the Function node, not what is passed in to the Function node.
That would explain why the Debug output doesn't show anything related to Paywave_.
It would help if you could add the Debug node alongside the Function node so we see exactly what message you are starting with. For example, in your Function node you reference msg.payload.Paywave_ in the first line, but msg.payload.Paywave_$ in the second line.
The reason msg.payload.Paywave_ appears with and without the is that when I type it directly into this message window the $ (dollar sign) disappears. Both cases have the dollar sign.
I have addded the debug node along side the function node but it does not show anything related to Paywave_$ (dollar sign) .
9/12/2019, 9:56:17 PMnode: 8b79517b.291efmsg : Object
I guess this is because it is coming from a S7 PLC node which can have multiple variables.
Essentially Paywave_ (dollar sign) is a float register coming from the PLC. When I change the vlue in the PLC the value in Paywave_ changes accordingly except that it has a multiple decimal places.
That shows that it is an object. There should be a triangle by it to expand it to see the objects contents as in this image from teh page about working with messages in the docs https://nodered.org/docs/user-guide/messages