From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Floating point array to string conversion

Solved!
Go to solution

Is there a way to convert an array of floating point and keep the decimals nicely as in the loop version below, but without any loop?

Untitled.png

0 Kudos
Message 1 of 12
(5,364 Views)

What's wrong with using a loop?

0 Kudos
Message 2 of 12
(5,348 Views)

I think it's less efficient with big arrays.

 

With 2D arrays you need two Loops, 3D arrays, three loops...

 

I'm just wondering if there's already a way and didn't know that.

0 Kudos
Message 3 of 12
(5,339 Views)
Solution
Accepted by topic author JimChretz

How about using "Array to Spreadsheet String" and "Spreadsheet String to Array" back to back.

 

Float2String.png

-----

The best solution is the one you find it by yourself
Message 4 of 12
(5,320 Views)

@Jimmy.chretien wrote:

I think it's less efficient with big arrays.

 

With 2D arrays you need two Loops, 3D arrays, three loops...

 

I'm just wondering if there's already a way and didn't know that.



Well, your problem as you posed it is only dealing with a 1D array for items names.

 

Why do you think loops would be less efficient, even for 2-D arrays and 3-D arrays?  When you use Auto-indexed For Loops, LabVIEW compiles the code to be quite efficient because is knows how much space to allocated based on the size of the original array.

 

Even if the loops were somehow less effiicient, that really isn't going to be noticeable until your arrays happen to be many orders of magnitude larger than what you have now.

 

It doesn't make sense to arbitrarily limit yourself from using one of the most basic programming structures because of some perceived inefficiency.  Prove to yourself you actually have a problem before you keep yourself from using the most basic of solutions.

0 Kudos
Message 5 of 12
(5,280 Views)

Well well well OriolesFan... I benchmarked the three solutions including the one with spreadsheet proposed by P@Anand and the Loop version is arround 10X slower than the 6 fix decimals, the spreadsheet one is 2X FASTER than the loop version which is interesting when your code requires some optimization.

 

Cheers

0 Kudos
Message 6 of 12
(5,257 Views)

If another solution works better for you that's great.

 

Before I'd claim that a solution with loops is bad and something else is 10x better, I'd be curious to see the code and the benchmarks.  A true benchmark can be very difficult to do as a number of apparently insignificant settings can skew the results.  Christian Altenbach here on the forums is the wizard for analyzing code, working with benchmarks, and determining what methods are the true optimums.  If you'd want, I'd say post your different methods and the code you used to benchmark them.

0 Kudos
Message 7 of 12
(5,251 Views)
I proposed the solution just as an alternative since you have asked for a code without loop.
I guess Christian might be doing a benchmark already in the background and pitch in at the right time.
-----

The best solution is the one you find it by yourself
0 Kudos
Message 8 of 12
(5,241 Views)

Well, with this idea implemented, we would not even have this disucssion 😄

0 Kudos
Message 9 of 12
(5,240 Views)

Personally, I would use a fixed number of decimal digits and right-align the strings in the control. No loop needed.. This will automatically also aling the decimal points for a clean look.

0 Kudos
Message 10 of 12
(5,236 Views)