# Parsing the scientific numbers to general numbers format

**URL:** <https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005>\
**Category:** General\
**Created:** [1 April 2020 05:19 UTC](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005 "2020-04-01T05:19:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Munier](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Munier](https://discourse.nodered.org/u/Munier)\
**Post date:** [1 April 2020 05:19 UTC](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005/1 "2020-04-01T05:19:18Z")

</div>

Hi Everyone, How can I parse a scientific numbers to general numbers format?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/671552b7de45f203a35e73ce5ba141bb86ea5b28.png)

---

<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:** [1 April 2020 06:34 UTC](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005/2 "2020-04-01T06:34:53Z")

</div>

Once you have extracted the number as a string then I think you should be able to use the Javascript `Number()` function to convert it, though I am on my phone and haven't actually tested it. Try it and see.

---

<div class="post-metadata">

**Author:** ![Munier](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Munier](https://discourse.nodered.org/u/Munier)\
**Post date:** [1 April 2020 07:05 UTC](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005/3 "2020-04-01T07:05:20Z")

</div>

> [@Colin](#):
>
> use the Javascript `Number()` function to convert it

I do not know how I can go about doing that can you please explain it a bit more?

---

<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:** [1 April 2020 08:50 UTC](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005/4 "2020-04-01T08:50:13Z")

</div>

Like this  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/2/72457a58e8094cad9e4f8effb7050cbdca301e26.png)

```auto
[{"id":"44eb473f.7fd67","type":"debug","z":"bdd7be38.d3b55","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":525,"y":1124,"wires":[]},{"id":"938ced83.62b15","type":"inject","z":"bdd7be38.d3b55","name":"","topic":"","payload":"0.10220000E003","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":148,"y":1125,"wires":[["60135a0a.80aa64"]]},{"id":"60135a0a.80aa64","type":"function","z":"bdd7be38.d3b55","name":"Convert to number","func":"msg.payload = parseFloat(msg.payload)\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":1124,"wires":[["44eb473f.7fd67"]]}]

```

---

<div class="post-metadata">

**Author:** ![Munier](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Munier](https://discourse.nodered.org/u/Munier)\
**Post date:** [1 April 2020 09:38 UTC](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005/5 "2020-04-01T09:38:37Z")

</div>

I have tried adding the code `msg.payload = parseFloat(msg.payload) return msg;` to the function node but it didn't work but I have copied the flow you have posted above and it works - quite strange

---

<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:** [1 April 2020 09:53 UTC](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005/6 "2020-04-01T09:53:37Z")

</div>

My code did assume that you had already split the number string out of the string from the file. I assumed that because you asked how to parse a number in scientific format. Are you actually asking how to extract those numbers from the string returned from the file node?  
If so then the first thing to do will be to split it up into useful pieces. Have you configured the file node to return the complete file as one object? If so then I suggest you start by changing it to return a message per line and then start by working out how to select the lines of interest.  
To do that you have to first work out what identifies the lines of interest, then work out how to throw away the other lines.

---

<div class="post-metadata">

**Author:** ![Munier](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Munier](https://discourse.nodered.org/u/Munier)\
**Post date:** [1 April 2020 10:45 UTC](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005/7 "2020-04-01T10:45:45Z")

</div>

> [@Colin](#):
>
> return a message per line and then start by working out how to select the lines of interest

I have configured the file node to return a message per line and I couldn't trace the line that carries the number of interest (went through all of the lines) as all the numbers are with no decimal point. There was only one line that share a (64) number but not 64.5.

---

<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:** [1 April 2020 11:21 UTC](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005/8 "2020-04-01T11:21:19Z")

</div>

Feed the file node into a debug node and show us what the last few lines look like.

---

<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:** [1 April 2020 11:29 UTC](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005/9 "2020-04-01T11:29:00Z")

</div>

Also show us what is actually in the file.

---

<div class="post-metadata">

**Author:** ![Munier](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Munier](https://discourse.nodered.org/u/Munier)\
**Post date:** [1 April 2020 11:41 UTC](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005/10 "2020-04-01T11:41:53Z")

</div>

> [@Colin](#):
>
> what is actually in the file.

!@rProfit\_Value,@rPerformance1\_Value,@rPerformance2\_Value,@rPenalty\_Value,@rTotal\_Value  
! 0.0000000000E+000, 0.0000000000E+000, -0.6407500000E+001, 0.0000000000E+000, -0.6407500000E+001  
!@rProfit\_Value,@rPerformance1\_Value,@rPerformance2\_Value,@rPenalty\_Value,@rTotal\_Value

F1, 0.1002200000E+003  
F2, 0.6450000000E+002  
F3, 0.3572000000E+002  
F4, 0.6450000000E+002  
F5, 0.3572000000E+002  
F6, 0.1002200000E+003

F1\_D, 0.1690000000E+001  
F2\_D, -0.5000000000E-001  
F3\_D, -0.1070000000E+001  
F4\_D, -0.3000000000E+000  
F5\_D, 0.7200000000E+000  
F6\_D, -0.1340000000E+001

---

<div class="post-metadata">

**Author:** ![Munier](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Munier](https://discourse.nodered.org/u/Munier)\
**Post date:** [1 April 2020 11:53 UTC](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005/11 "2020-04-01T11:53:30Z")

</div>

Here is what I get

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/0/805039c4fb5a774ac25fabda2a9b46505e3f3879.png)

---

<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:** [1 April 2020 12:36 UTC](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005/12 "2020-04-01T12:36:54Z")

</div>

Show us how you have configured the file node.  
On the debug is that last lines as I asked, or is there only one?

---

<div class="post-metadata">

**Author:** ![Munier](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Munier](https://discourse.nodered.org/u/Munier)\
**Post date:** [1 April 2020 12:50 UTC](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005/13 "2020-04-01T12:50:22Z")

</div>

I thought you meant the function node connected to the debug node!

---

<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:** [1 April 2020 13:16 UTC](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005/14 "2020-04-01T13:16:13Z")

</div>

No, I said

> [@Colin](#):
>
> Feed the file node into a debug node and show us what the last few lines look like.

The data you are trying to interpret is coming out of the File node isn't it? What is the function node doing anyway?  
Perhaps I don't understand what you are trying to do. I thought you were trying to read a file and extract the information from the data in the file.

---

<div class="post-metadata">

**Author:** ![Munier](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Munier](https://discourse.nodered.org/u/Munier)\
**Post date:** [1 April 2020 13:29 UTC](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005/15 "2020-04-01T13:29:49Z")

</div>

> [@Colin](#):
>
> what you are trying to do

What I am trying to do is change the format of the data below i.e F1, 0.1002200000E+003  
I want it to read as F1, 100.22 that is all. Can you save the following file and try it?

!@rProfit\_Value,@rPerformance1\_Value,@rPerformance2\_Value,@rPenalty\_Value,@rTotal\_Value  
! 0.0000000000E+000, 0.0000000000E+000, -0.6407500000E+001, 0.0000000000E+000, -0.6407500000E+001  
!@rProfit\_Value,@rPerformance1\_Value,@rPerformance2\_Value,@rPenalty\_Value,@rTotal\_Value

F1, 0.1002200000E+003  
F2, 0.6450000000E+002  
F3, 0.3572000000E+002  
F4, 0.6450000000E+002  
F5, 0.3572000000E+002  
F6, 0.1002200000E+003

F1\_D, 0.1690000000E+001  
F2\_D, -0.5000000000E-001  
F3\_D, -0.1070000000E+001  
F4\_D, -0.3000000000E+000  
F5\_D, 0.7200000000E+000  
F6\_D, -0.1340000000E+001

---

<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:** [1 April 2020 13:49 UTC](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005/16 "2020-04-01T13:49:12Z")

</div>

So feed the output of the file node into a debug node and show us what you get.

---

<div class="post-metadata">

**Author:** ![Munier](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Munier](https://discourse.nodered.org/u/Munier)\
**Post date:** [1 April 2020 13:51 UTC](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005/17 "2020-04-01T13:51:43Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/c/4c48b7f2d9189952814c71dc74fdf633efdb8676.png)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [1 April 2020 14:01 UTC](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005/18 "2020-04-01T14:01:03Z")

</div>

Hi @Munier

I think you've shown us the file contents enough times to see what you have got.

I assume you want to replace _all_ such numbers including those in the first few lines?

If so, you can use the following Function node code:

```auto

msg.payload = msg.payload.replace(/(-?\d+\.\d+E[-+]\d+)/g, function(v) { return Number(v) })
return msg;

```

This uses a regular expression to find all of the numbers and replaces them with the parsed version.

---

<div class="post-metadata">

**Author:** ![Munier](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@Munier](https://discourse.nodered.org/u/Munier)\
**Post date:** [1 April 2020 14:08 UTC](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005/19 "2020-04-01T14:08:54Z")

</div>

> [@knolleary](#):
>
> msg.payload = msg.payload.replace(/(-?\d+.\d+E[-+]\d+)/g, function(v) { return Number(v) }) return msg;

I have used the function node code you've suggested it gives the same scientific format for the numbers.  
I can post the bitmap if you like.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [1 April 2020 14:12 UTC](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005/20 "2020-04-01T14:12:36Z")

</div>

Can you confirm where you put the Function node? A screenshot of your flow may help.

[Next page](https://discourse.nodered.org/t/parsing-the-scientific-numbers-to-general-numbers-format/24005.md?page=2)
