LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

convert exponential string to number - problem

hi everyone. I'm having trouble with this conversion. Here's the thing. I am acquiring data via the serial port and get the read values in string format. I then convert said values to number. That is, if the string is for example "+1.330-6" (that is the format the instrument sends), I then modify the string (with the VI concatenate string) to be "+1.330e-6", which is the actual value. Then, using the Convert exp String to Number VI, I get the corresponding value of 1.330E-6. So far so good. The problem is that the program isn't working for certain values of exponential. If the value sent through the serial port is "1.330e-4" the conversion to number only displays 1.33 and totally ignores the "e-4", same thing happens with "e-5" and "e-7" but works well with "e-3".
 
In a vain attempt to solve this, I modified the string using capital E instead of e, but get the same result.
 
Does anyone have any idea of what might be happening?
0 Kudos
Message 1 of 8
(5,687 Views)
I noticed something else in my system. This behaviour is NOT constant. That is, in some occasions it might work correctly for "e-4", but not for "e-5", the point is that it doesn't work for all exponential values, but it works for different ones every time I run the program. Please help!
0 Kudos
Message 2 of 8
(5,666 Views)

My best guess would be that the string you're converting has a space between the mantissa and the E (or e) or that there is some other character there that isn't part of a number. Could there be two E's? The conversion routiine interprets that as the end of the number, ignoring any remaining characters.

Rod.

 

0 Kudos
Message 3 of 8
(5,666 Views)

Thank you Rod. Unfortunately I don't think that is the problem. As you can see in the atteched images, the array first displays the acquired data exactly as sent by the instrument. The first group of string indicators (n1-n16) are the modified strings. As you can see, there's only one "E" and no spaces. And finally, the third group are numeric indicators, where the conversion from string to number is displayed.

As shown in the images, sometimes it works, sometimes it doesn't...I really hope someone knows what's going on.

Ali.

Download All
0 Kudos
Message 4 of 8
(5,659 Views)

...or instead of manipulating the string use this

 

Rod.

 

Message 5 of 8
(5,648 Views)
It *IS* your string format at fault. Where it goes wrong you have (for example) +9.23-e5
The conversion (correctly) interprets this as 9.23 and discards the remainder of the string as a - cannot be part of a number where it was seen.
 
Anyway, try what was in my last post. It doesn't need any string manipulations.
 
Rod.
 
 
0 Kudos
Message 6 of 8
(5,640 Views)

Hi Ali

  See the attachment. it  will help u.

Rigil Kumar

 

0 Kudos
Message 7 of 8
(5,636 Views)

Thank you! That solved the problem just fine. I had just noticed the length mantissa was varying.

Thanks again.

Ali.

0 Kudos
Message 8 of 8
(5,624 Views)