What is the appropriate/standard method for converting from a double to int32 in Labview?
I'm counting digits in a number say, "98.7" yields 9 tens, 8 ones, 7 tenths.
Normally in "C" I would just do something like:
ntens = int(dblNum/10.0);
dbltmp = dblNum-10.0*ntens;
nones = int(dbltmp);
ntenths = int(10*(dbltmp-nones));
I've tried variousl methods in Labview, but there are always special cases to handle.
I can use the "Round towards -Infinity" but I'll have to check for positive numbers and it also appears to have round-off issue. For example, when my number is "1.2", it maps it to "1.1". I've used a probe to monitor the value of "2" going into the "Round towards -Infinity" with a "1" coming out, Labview 8.6.
I've read some of the other posts on this topic, but I've not seen a recommended procedures.
This seems like a pretty common thing to do . Is there a simple way to do this?
I've spent way too much time on this and it should be easy.
Can you explain in a few more sentences what you are actually trying to do?
Do you simply want each digit as an I32 number? How many digits do you want?
You need to be aware that many fractional floating point numbers that are nice in decimal, cannot be exactly represented in binary, thus your 1.2 is actually 1.19999999999999996000, leading to the observed problem. This happens in any programming language.
Multiply the number with 10 first, round to nearest, convert to integer, and extract the three digits?
To convert from float to integer, the I32 function you are using already does that. It happens to round to nearest as well. But the text of your message says you want more than that. You want a round towards zero.
>Can you explain in a few more sentences what you are actually trying to do?
>Do you simply want each digit as an I32 number? How many digits do you want?
I want an integer count of each digit. My number ranges is from 0.1 - 99.9, so there are 3 digits, tens, ones, tenths. I've already figured out a simple work around the limitation of the LabVIEW int32 conversion, (which rounds instead of truncates). I just multiple my number by ten so the ranges is 1 - 999. Then I can work in integer math and I don't have any rounding errors. Also I'm using the "Quotient & Remainder" function which includes a floor calculation.
Regarding "GetDigits.vi", I know this will work, but
I'd rather avoid the conversion to ascii and parse the string just to find out the value of a digit.
PointOnePa wrote: I've used a probe to monitor the value of "2" going into the "Round towards -Infinity" with a "1" coming out, Labview 8.6.
That most likely means the value was below 2 but rounded in the probes display to 2 (1.9999999999999995 or something similar).
Such calculation are logarithmic based and should not be done with normal divides (in any language).
Here's a solution that should work for:
It returns an array for every position in the base writing system:
This was for base 10, here are the results for base 2 (binary):
I don't have any negative numbers in my application, so I'm not concerned with operation with negative numbers.
My input ranges is from 0.1 to 99.9. The input is a flow rate in ml/hour.