Double quotes and variable

573 views
Skip to first unread message

Raphael MANZANO

unread,
Nov 5, 2017, 10:48:39 AM11/5/17
to Node-RED
Hello.

First, excuse my bad english ... i'm French ...


This is my problem: I want to use node-red function to resend a value from one mqtt topic to another.

I use this function to round the value:

var nombre = msg.payload;
arrondi = nombre*100;         
arrondi = Math.round(arrondi);
arrondi = arrondi/100;
msg.payload = {};
msg.payload.idx = 1749;
msg.payload.svalue = arrondi;
return msg;



It's work fine but i need to add double quote before and after arrondi value.


For the moment the msg is like this: { "idx": 1749, "svalue": 20.6 } and i would like it be like this: { "idx": 1749, "svalue": "20.6" }



I've try to escape double quotes (\") but it doesn't work :(

Can someone explain me how to do please ?

Thanks a lot.


Nick O'Leary

unread,
Nov 5, 2017, 10:59:26 AM11/5/17
to node...@googlegroups.com

Currently, arrondi is a number type and you need it to be a String.

Easiest way to do that:

msg.payload.svalue = ""+arrondi;

Regards,
Nick


--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/5ae219e7-cf2f-44aa-b466-570d3311f5e4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Raphael MANZANO

unread,
Nov 5, 2017, 2:30:52 PM11/5/17
to Node-RED
Thank you: it's working.

Regards
Reply all
Reply to author
Forward
0 new messages