# Regarding obtaining a number

**URL:** <https://discourse.nodered.org/t/regarding-obtaining-a-number/20906>\
**Category:** Dashboard\
**Created:** [27 January 2020 10:32 UTC](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906 "2020-01-27T10:32:57Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![jatin.pachisia](https://avatars.discourse-cdn.com/v4/letter/j/bbce88/32.png) [@jatin.pachisia](https://discourse.nodered.org/u/jatin.pachisia)\
**Post date:** [27 January 2020 11:08 UTC](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906/21 "2020-01-27T11:08:56Z")

</div>

TT=170ms OTL=0mm CC=1 OI=1600384290470000000010 C128 63% ST=0 RA=46 CL=20 CS=\_63 DIR=1 OD=524 FC=498

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [27 January 2020 11:11 UTC](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906/22 "2020-01-27T11:11:05Z")

</div>

Ok, interesting.

Let's practice _formatting_ the stuff you paste.

Top left of the keyboard. (Left of the number 1) there is a key.  
Press it. Then paste from the clipboard and press that button again.

That should make it look something like:

`TT=170ms OTL=0mm CC=1 OI=1600384290470000000010 C128 63% ST=0 RA=46 CL=20 CS=_63 DIR=1 OD=524 FC=498`

---

<div class="post-metadata">

**Author:** ![jatin.pachisia](https://avatars.discourse-cdn.com/v4/letter/j/bbce88/32.png) [@jatin.pachisia](https://discourse.nodered.org/u/jatin.pachisia)\
**Post date:** [27 January 2020 11:12 UTC](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906/23 "2020-01-27T11:12:08Z")

</div>

TT=169ms OTL=0mm CC=1 OI=1200384290470000000010 C128 17% ST=0 RA=49 CL=20 CS=\_17 DIR=1 OD=414 FC=498

This is what i obtain now. I have deleted the json node and the other otput node as well

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [27 January 2020 11:13 UTC](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906/24 "2020-01-27T11:13:04Z")

</div>

So you could feed that output to a `split` node and split it on a `space`, feed to output to a switch and test if the payload contains `OI=`

Send that output to a function node and strip out the 'OI=' and you should be set.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [27 January 2020 11:25 UTC](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906/26 "2020-01-27T11:25:53Z")

</div>

Here is a basic picture of what you need to do:

1 - ignoring the `TCP in` node not being set correctly.  
2 - Connect a `split` node as shown.  
3 - Connect a `switch` node as shown.  
4 - Configure the `split` node as shown.  
Note there is a \> space \< in the field which you can't see. By default it has `\n`. Delete that and press the space bar.  
5 - Configure the `switch` node as shown. That is OI (capitol i) `OI=`

That will get you the result you need to this point.

 ![Screenshot from 2020-01-27 22-20-32](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/2/a258bf23a782c4972e7e482ccb5e2c11d13854de.png)

 ![Screenshot from 2020-01-27 22-20-42](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/9/098323d9413fd9353af0c6bed014a133af3b23a9.png)

 ![Screenshot from 2020-01-27 22-20-47](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/6/8694c70e2a970148f92c2da154098fcc515a6b7c.png)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [27 January 2020 11:37 UTC](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906/27 "2020-01-27T11:37:58Z")

</div>

Andrew, that is not enough. Jatin wants to get the number portion of the string.

@jatin.pachisia so you have `OI=1200384290470000000010` and you want to get rid of the first 7 characters of that string and return the results as a number (384290470000000010)...correct?

I also notice that inone o your debug's there is a `...OI=4[]*NoRead*...` which I assume you want to ignore so you will need to check for that string and skip it if it exists. In the switch node, first check if the input string contains _NoRead_' and ignore it. Make sure to set the switch node to `stop after first match`

---

<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:** [27 January 2020 12:25 UTC](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906/28 "2020-01-27T12:25:19Z")

</div>

@jatin.pachisia do you really want it as a number, or do you want it as a string containing those digits? If you don't know then tell us what you want to do with it after you have got it.

---

<div class="post-metadata">

**Author:** ![jatin.pachisia1](https://avatars.discourse-cdn.com/v4/letter/j/a4c791/32.png) [@jatin.pachisia1](https://discourse.nodered.org/u/jatin.pachisia1)\
**Post date:** [27 January 2020 13:31 UTC](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906/29 "2020-01-27T13:31:37Z")

</div>

Okay. I had to make a new account in order to be able to reply. Since a new user has limited amount of messages. I did whatever I was asked to above. I put in a split node and the switch node adn set them to use as mentioned above. What i need to do is to be able to split the variable into two. The value i see now is `OI=200384290470000000010`  
The 20 here is the index number and the 0038 until 0 is the number i need as the output. My work is to basically be able to obtain this number which my barcode scanner will be reading of pallets. According to the numbers, i can decide where my automated vehicle should be heading towards to pick up the pallets. I think i will be needing a function node

---

<div class="post-metadata">

**Author:** ![jatin.pachisia1](https://avatars.discourse-cdn.com/v4/letter/j/a4c791/32.png) [@jatin.pachisia1](https://discourse.nodered.org/u/jatin.pachisia1)\
**Post date:** [27 January 2020 13:36 UTC](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906/30 "2020-01-27T13:36:54Z")

</div>

The value that i obtain can be in Hexadecimal or ascii format. So i will need to know how to be able to code in order to be able to understand for future purposes. When the bar code scans a code of the pallete, I get the index number and the code. Which is perfect now. However, i am trying to split them into two parts. Because then later i will be able to send the output to some other place.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [27 January 2020 14:00 UTC](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906/31 "2020-01-27T14:00:16Z")

</div>

So you want to remove the first 5 characters not nescessaraly `IO=20` since I see `IO=16` in an earlier debug you posted.

I would do it wit a change node using two JSONata expressions - the first gets rid of the first 5 characters, the second returns it as a number  
 ![Screen Shot 2020-01-27 at 8.58.40 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/a/0ac86f3ee908f07ece59a62f9f6141674ec57b3b.png)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [27 January 2020 14:16 UTC](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906/32 "2020-01-27T14:16:22Z")

</div>

(just thinking out loud.... I would also put the 16 or 20 (last two chars of the "header" into msg.topic... just in case... 😉

---

<div class="post-metadata">

**Author:** ![jatin.pachisia1](https://avatars.discourse-cdn.com/v4/letter/j/a4c791/32.png) [@jatin.pachisia1](https://discourse.nodered.org/u/jatin.pachisia1)\
**Post date:** [27 January 2020 14:32 UTC](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906/33 "2020-01-27T14:32:49Z")

</div>

So i am supposed to add a change node after my switch node ? with the above mentioned ways. I will also be needing an inject node right ?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [27 January 2020 15:11 UTC](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906/34 "2020-01-27T15:11:47Z")

</div>

What have you tried and are you having an issue now?

---

<div class="post-metadata">

**Author:** ![jatin.pachisia1](https://avatars.discourse-cdn.com/v4/letter/j/a4c791/32.png) [@jatin.pachisia1](https://discourse.nodered.org/u/jatin.pachisia1)\
**Post date:** [27 January 2020 15:17 UTC](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906/35 "2020-01-27T15:17:43Z")

</div>

`Invalid JSONata expression: Unable to cast value to a number: "\n00384290470000000010\r\n"`

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/6/06b0ddaa71d2a02766086af34dfd773dd0b7a68e.png)  
This is what i get when i tried using the change node and using the JsoNata expressions

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [27 January 2020 16:43 UTC](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906/36 "2020-01-27T16:43:13Z")

</div>

Please export your flow and attach it to a reply. Then put a `debug` node (set to display the complete msg object) on the output of the `TCP` node.

When you have the debug, click the payload to display the complete value in it. Copy that value and paste it into your reply too.

---

<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:** [27 January 2020 16:54 UTC](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906/37 "2020-01-27T16:54:34Z")

</div>

I really don't think you want to convert it to a number. If you do that you will lose some of the least significant digits as the largest integer that can be held in javascript is 9007199254740992. I think you want to keep it as a string of digits.  
If you do convert it the result will be that the number in the string above will be stored as 3.8429047\*10^17 and you will lose the 10 on the end.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [27 January 2020 20:19 UTC](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906/38 "2020-01-27T20:19:33Z")

</div>

Ok, but I made a flow which injected the string he posted.

The `switch` node worked because it looked for 'OI=` in the string.  
Yes, I know there are better ways. But I did test it before posting.

Stripping the other stuff to get the `3842904.....` would be the next step.

---

<div class="post-metadata">

**Author:** ![jatin.pachisia1](https://avatars.discourse-cdn.com/v4/letter/j/a4c791/32.png) [@jatin.pachisia1](https://discourse.nodered.org/u/jatin.pachisia1)\
**Post date:** [28 January 2020 09:06 UTC](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906/39 "2020-01-28T09:06:40Z")

</div>

`Invalid JSONata expression: Unable to cast value to a number: "\n00384290470000000010\r\n"`  
i cannot export flows and attach them here as i am a new user. But this is what the complete value says when i attached the change node after the switch like you asked me to.

 ![Capture.PNG 5](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/e/0e4ca1adaeca55565cfc9cf8a03c771eb0d8c076.png)

---

<div class="post-metadata">

**Author:** ![jatin.pachisia1](https://avatars.discourse-cdn.com/v4/letter/j/a4c791/32.png) [@jatin.pachisia1](https://discourse.nodered.org/u/jatin.pachisia1)\
**Post date:** [28 January 2020 09:09 UTC](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906/40 "2020-01-28T09:09:44Z")

</div>

sorry that was the wrong image

 ![Capture.PNG6](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/4/94d8441549dab9e83e7f624745e4a10db65b4778.png)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [28 January 2020 10:14 UTC](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906/41 "2020-01-28T10:14:17Z")

</div>

1. Why didn't you add the code to the switch to ignore the `*NoRead*` entries?
2. did you change the `split` value or the `TCP` 'Output' settings?
3. In your prior debug outputs there were no special characters, now there are, what changed?

Please put a 'debug' node (set to display the 'Complete msg object') on the output of the `TCP` node so I can see what the data is again.

[Previous page](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906.md?page=1)

[Next page](https://discourse.nodered.org/t/regarding-obtaining-a-number/20906.md?page=3)
