Parsing the scientific numbers to general numbers format

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.

I was trying to go down the route of getting multiple lines, one msg per line, and then use a switch node to select the right line and go from there, rather than use a technique that will probably not be fully understood.

Also I believe the requirement is to extract just that one number and ignore the rest.

1 Like

I believe you pressed "reply" too soon, before your computer finished uploading the image.

These are the numbers I want to parse.
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

@Munier the screenshot you've tried to share has failed to share. Please retry sharing it.

Also, please make it clear if you goal is to get the same text you have, just with the numbers replaced, or if you want to also access the individual values and do something else with them.

My Goal is to reformat

F1, 0.1002200000E+003 to F1, 100.22
F2, 0.6450000000E+002 to F2, 64.500
F3, 0.3572000000E+002 to F3, 35.720
F4, 0.6450000000E+002 to F4, 64.500
F5, 0.3572000000E+002 to F5 35.720
F6, 0.1002200000E+003 to F6, 100.22

F1_D, 0.1690000000E+001 to F1_D, 1.6900
F2_D, -0.5000000000E-001 to F2_D, 0.5000
F3_D, -0.1070000000E+001 to F3_D, 1.0700
F4_D, -0.3000000000E+000 to F4_D, 0.3000
F5_D, 0.7200000000E+000 to F5_D, 0.7200
F6_D, -0.1340000000E+001 to F6_D, 1.3400

Yes, I have some bandwidth issues.

You screenshot shows you have the Function code correct, but it doesn't show where the Function node is in the flow. All I can see is an Inject node connected to a Function node and nothing after that. It looks like it is that Function node you have put this code into.

Does that mean you are injecting the text you want to handle from the Inject node directly?

Or is there still a File node later in the flow?

If the File node comes later in the flow, then how do you imagine the Function node is able to modify the contents if you have put it before the contents of the file is loaded?

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