# Convert integer value to word

**URL:** <https://discourse.nodered.org/t/convert-integer-value-to-word/82108>\
**Category:** General\
**Created:** [17 October 2023 12:30 UTC](https://discourse.nodered.org/t/convert-integer-value-to-word/82108 "2023-10-17T12:30:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmgimo75](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jmgimo75](https://discourse.nodered.org/u/jmgimo75)\
**Post date:** [17 October 2023 12:30 UTC](https://discourse.nodered.org/t/convert-integer-value-to-word/82108/1 "2023-10-17T12:30:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 October 2023 13:11 UTC](https://discourse.nodered.org/t/convert-integer-value-to-word/82108/2 "2023-10-17T13:11:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [17 October 2023 14:11 UTC](https://discourse.nodered.org/t/convert-integer-value-to-word/82108/3 "2023-10-17T14:11:30Z")

</div>

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`

```auto
msg.payload = msg.payload.toString(16).split('0x')[0].padStart(4, '0')
return msg

```

Proof:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/3/13aa6ad45e801f878a419beff6fb2b1d2db55fcd.png)

---

<div class="post-metadata">

**Author:** ![omrid](https://avatars.discourse-cdn.com/v4/letter/o/77aa72/32.png) [@omrid](https://discourse.nodered.org/u/omrid)\
**Post date:** [17 October 2023 14:22 UTC](https://discourse.nodered.org/t/convert-integer-value-to-word/82108/4 "2023-10-17T14:22:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [17 October 2023 14:27 UTC](https://discourse.nodered.org/t/convert-integer-value-to-word/82108/5 "2023-10-17T14:27:40Z")

</div>

> [@omrid](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [16 December 2023 14:27 UTC](https://discourse.nodered.org/t/convert-integer-value-to-word/82108/6 "2023-12-16T14:27:45Z")

</div>

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