LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

string to decimal rounding issue

Solved!
Go to solution
Hello everyone, I have a large amount of data that I have to plot into graphs and Im trying to automate the process. Right now Im reading the data from a *.txt file and when I try to convert it into an array of numbers all of the decimal places disapper. What am I doing wrong?? Bellow is my VI
Bruno Noronha

Certified LabVIEW Associate Developer





Using LabVIEW 8.6
0 Kudos
Message 1 of 27
(4,697 Views)
My computer isnt letting me attach the VI
Bruno Noronha

Certified LabVIEW Associate Developer





Using LabVIEW 8.6
0 Kudos
Message 2 of 27
(4,689 Views)

What function are you using to convert?

You might be telling it to only return intergers.

 

Your code was not posted

Omar
0 Kudos
Message 3 of 27
(4,687 Views)

To me, it's VERY unintuitive, but you must use "Fract/Exp String To Number" instead of "Decimal String To Number."  While technically, "decimal" stands for "base10," I think most people interpret it as a number with a decimal point.  LabVIEW uses "decimal" as it does "octal" and "hexadecimal," which is intirely correct, but confusing.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 4 of 27
(4,679 Views)

@billko wrote:

To me, it's VERY unintuitive, but you must use "Fract/Exp String To Number" instead of "Decimal String To Number." 


That is one possibility.

 

How are you reading the file? You should also make sure that your localized decimal point is corrrectly handled. Some countries use a period (1.234) and other use a comma (1,234) as decimal seperator and an incorrect setting will drop all fractional parts. Can you attach a typical text file?

0 Kudos
Message 5 of 27
(4,673 Views)

Here in Brazil we use commas instead of points for decimal seperation. Ive tried using a search/replace VI to work with both but the end result is the same.

 

 

Hmm my company's IT department has restricted the internet in a way that I cant upload anything. I'll walk you through the ultra-simple block diagram.

 

1) I open the *.TXT file using an OPEN/CREATE/REPLACE VI

2) I use a Read From Text File.VI to read the data and a Replace SubString.VI to exclude 11 characters of header at the begining of my file

3) I now have a string with a couple thousand of lines each line corresponds to a point which I intend to plot on a graph. here Ive tried two different ways of handling the data both producing the same results, method 1 was using the Spreadsheet String to Array.VI and method 2 was opeing a for loop and choosing the Pick Line.vi followed by a Decimal String to number.vi

 

In both cases a number that originally is -6.7845132 on my string is displayed as -6 by my numeric indicator.

 

Again it doesnt matter wether I  used -6,7845.... or -6.7845... the end result is still -6

Bruno Noronha

Certified LabVIEW Associate Developer





Using LabVIEW 8.6
0 Kudos
Message 6 of 27
(4,623 Views)
Solution
Accepted by topic author bnoronha

@bnoronha wrote:

followed by a Decimal String to number.vi


 That's your problem. As previously stated by Bill, you need to use the Fract/Exp String to Number function. Please use the LabVIEW Help. It would have told you what that function does.

 

I don't quite understand all of the gymnastics you are doing with trying to read the file. Why are you using Replace SubString to remove the first 11 characters? String Subset would be more appropriate. Have you tried simply using Read From Spreadsheet File? You can change the format string to specify localization codes (see the LabVIEW Help).

Message 7 of 27
(4,618 Views)

Wow I feel like a dunce...

 

Fract/Exp String worked. I guess I saw decimal and figured that the solution was there...

 

for some reason I figured that Read From Spreadsheet couldnt be used for *.txt files.

 

 

Replaced 5 .VIs with one.

 

 

many thanks  

 

 

Bruno Noronha

Certified LabVIEW Associate Developer





Using LabVIEW 8.6
0 Kudos
Message 8 of 27
(4,612 Views)

I think this is somewhat the same problem that I have. I'm also using Decimal String to Number and my input is a string array with a bunch of the same data which is 32,768. When it goes through the Decimal String to Number, it rounds it to 32 and this number is being manipulated further, but I do not want it to be a 32. I would prefer it to be 32.768. (Scaling is included so of course it is actually 32,000 and 32,768 respectively). I have tried replacing my Decimal String to Number but I still get an array of 32. Any ideas?

0 Kudos
Message 9 of 27
(4,529 Views)

I replaced the Decimal String to Number with the Fract/Exp String to Number block***

0 Kudos
Message 10 of 27
(4,527 Views)