From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
08-16-2009 01:39 PM
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.
08-16-2009 02:00 PM
I guess I can get around the roundoff issue
by changing the order of execution the calculation.
08-16-2009 02:10 PM
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.
You could:
Multiply the number with 10 first, round to nearest, convert to integer, and extract the three digits?
08-16-2009 02:13 PM - edited 08-16-2009 02:16 PM
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.
See this.
08-16-2009 02:28 PM
08-16-2009 02:29 PM
>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.
08-16-2009 02:31 PM
Try your code with a negative number and see if it makes sense.
08-16-2009 02:33 PM
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.
08-16-2009 02:35 PM
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):
Good luck,
Ton
08-16-2009 02:37 PM
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.