Parsing the scientific numbers to general numbers format

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

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.

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

Like this
image

[{"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"]]}]

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

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.

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.

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

Also show us 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

Here is what I get

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

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

No, I said

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.

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

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

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:


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.

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.

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