LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Integer digits to double numeric - elegant way?

Solved!
Go to solution

Hello,

 

This seems very simple, but I feel my solution is a quick and dirty one. How would you do it?

Scenario: i have 5 integer inputs in an array (digits). I also know the location (which varies time by time) of the decimal point, so I have another input as "multiplier".

My first thought is this:

 

digits_to_numeric.png

0 Kudos
Message 1 of 7
(3,210 Views)
Solution
Accepted by Blokk

That seems to work, but it's certainly "not obvious by looking at it".  This might not be as "efficient" (but who cares, unless you are doing gazillions of these), but the logic is simple -- take an array of digits, make it a number, divide by the multiplier.  Given that the answer is a Float, and doing a single divide/multiply tends to avoid "float" issues, I transformed the digits into an integer string, floated it, then divided.  Here's a Snippet (I apologize for it being LabVIEW 2017, which I don't generally use, but was running on a Test machine to answer another Forum question):

Blokk Problem.png

Bob "Simple" Schor

 

Message 2 of 7
(3,176 Views)

First i also thought about to go with number to string function, but i felt a number-string-number conversion is too much. But actually now i see that, it is more compact, much better! 🙂

0 Kudos
Message 3 of 7
(3,171 Views)

Look Ma! No loops!

 

NoLoop.png

 

(Of course this makes certain assumptions, such that the array always has 5 elements. Also SGL would probably be sufficient for 5 decimal digits. You might even do the array constant and summing in e.g. I32)

Message 4 of 7
(3,161 Views)

Hi,

 

another try using ASCII:

check.png

(The question was for an "elegant way", not the best performing… 🙂

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 7
(3,120 Views)

I had the strong feeling, I will get lots of options, including quite "exotic" ones! 🙂

For the driver, I will use this straightforward approach, one of the solutions above. I modified it a bit, to reflect the range table values and prefixes in a more direct way. So for example, for Ohm, the largest range is xxx.xx MOhm, so the multiplier becomes 100M:

Spoiler
range_1.png

digitzs1.png

0 Kudos
Message 6 of 7
(3,116 Views)

That should be pretty efficient and relly neat!

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 7
(3,100 Views)