Convert integer value to word

Hello good.
I have a question with an entry reading.
I have an entry that I cannot read in word (from 0000 to 03e8) on your site I get it (from 0 to 1000)
My question is. Can I convert the input integer value to a word (WORD)?
How can I do it???

Thanks a lot

What do you mean by a word and what are you going to do with it that needs it in that form?

So essentially you want to convert a number to a hexaceimal format (less the leading 0x)?

This can be achieved in plain old JavaScript in a function node.

As you have provided nowhere near enough info, I will make assumptions:

  • I am assuming msg.payload is a number
  • I am assuming you want to put the result into msg.payload
msg.payload = msg.payload.toString(16).split('0x')[0].padStart(4, '0')
return msg

Proof:
image

I would add a small comment (and happy to hear feedback if I'm missing something):
I prefer using String() rather than .toString(). toString() generates a runtime error and aborts the message forwarding if msg.payload is undefined or null, while String() returns valid strings with the value 'undefined' or 'null' respectively.

The issue there is you wont have a catchable error & that "string" will displayed (or store in DB or whatever the OP intends to do with it)

Of course, they may want that and your response is perfectly valid - but alas, too little info provided.

1 Like

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