LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

format 2D array of strings to create columns x characters wide and numbers formatted to 3 decimal places

I have a problem that at first seemed easy, then complex and now it seems it should be easy (but the NI engineer can't get to the bottom of it, since an NI VI seems to be not working correctly).  I have an array of strings - some are alpha and some numeric.  I want to format the array so that my columns are x number of characters wide and any numeric strings are truncated to 3 decimal places.  I thought (and the NI engineer confirmed) that I should be able to use the Array to Spreadsheet String VI to do this, with a format string of %20.3s of %20.3f to get colun widths of 20 characters and "precision" to 3 decimal places.  Not so!  Cannot get this to work.  The problem surfaces with repeating decimals.  PLease see attachments.  I want to format the array so that the repeating decimal in t Actual Concentration column is truncated to 3 decimal places.
Download All
0 Kudos
Message 1 of 4
(3,092 Views)
THis seems to be a continuation from here. You might want to keep it all in one place.
0 Kudos
Message 2 of 4
(3,088 Views)
I would point out that the string format "%20.3s" tells LV to use 3 characters from the string and pad to a total width of 20 characters.  This is probably not what you are hoping for.  I would suggest you scan through the array and if the value is a number convert to a DBL and back with the %20.3f format string, and if it is a string use the %20s format (or whatever padding you want).  I'd use the Scan Value vi, if the output string matches the input, treat it as a string, otherwise treat it as a number.
0 Kudos
Message 3 of 4
(3,084 Views)

Here's a primitive version (LV 8.6) that formats all numerics with 3 decimal digits and 20 width (use a fixed width font for the table (e.g. courier), else it will never look quite right).

 

Most likely you need to make it more bulletproof, right now it would fails if any of the texts contain numerics, for example.

 

Still, it should give you something to start width.

 

0 Kudos
Message 4 of 4
(3,082 Views)