Showing results for 
Search instead for 
Did you mean: 

Integer digits to double numeric - elegant way?

Go to solution



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:



0 Kudos
Message 1 of 7
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

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! Smiley Happy

0 Kudos
Message 3 of 7

Look Ma! No loops!




(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)

LabVIEW Champion Do more with less code and in less time
Message 4 of 7



another try using ASCII:


(The question was for an "elegant way", not the best performing… :-)

Best regards,
CLAD expired, using 2009SP1 + LV2011SP1 + LV2017 (+LV2018 sometimes) on Win7+cRIO
Kudos are welcome Smiley Wink

Message 5 of 7

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

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:



0 Kudos
Message 6 of 7

That should be pretty efficient and relly neat!


G# - Award winning reference based OOP for LV, for free! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
0 Kudos
Message 7 of 7