LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

double to boolean conversion

Hi..
How do i convert Double value to Boolean(TRUE/FLASE)??
Thank you,
Ranjith
Message 1 of 14
(25,825 Views)
There are a few ways...
 
Since you have doubles, you may have values other than 1 & 0, so I would simply wire an "not equal to 0" to the double and the output will be a boolean.  If a 0 is in the double you'll get a FALSE.  Al other values will give you a TRUE.
 
R
Message 2 of 14
(25,808 Views)
Look on your comparison palette. The Greater Than, Greater Than or Equal, In Range and Coerce, etc. Unless you would restrict an integer to be only 0 or 1, it's the same for any numeric data type.
0 Kudos
Message 3 of 14
(25,807 Views)
thank you.. good idea..
0 Kudos
Message 4 of 14
(25,802 Views)
Excellent advice. A "direct" approach will likely cause unexpected behaviour when testing for a 0 or 1 due to conversion....
0 Kudos
Message 5 of 14
(25,793 Views)
If the numeric values are calculated (rather than just being entered into a control or read from a file), it is possible that a value very close to, but slightly different from, zero may occur. Using the =Zero comparison on a calculated DBL may not give the result you expect. In this case the In Range and Coerce is a better choice (as has been suggested above). Set the limits to +/- 1E-6 or other small value suitable for your requirements.

I found this occurring often enough that I created a VI which I call Approximately Equal to Zero. It is used whenever I need to make zero comparisons on non-integer numerics.

Lynn
0 Kudos
Message 6 of 14
(25,790 Views)
Lynn, could you share that VI?  Smiley Happy
0 Kudos
Message 7 of 14
(25,788 Views)
Here it is. Saved for version 8.0.

Lynn
0 Kudos
Message 8 of 14
(25,769 Views)

As Johnsold mentionned, converting a double to boolean can provide unexpected results.

Actually, this is not what I had in mind because you would need to define "what is zero?"  What about cases containing negatives?

So the best alternative would be to identify the range that would be considered zeros..

I don't have LV on this PC, so I couldn't open Johnsold's example, but I'm sure it should be a good one.  🙂

R

0 Kudos
Message 9 of 14
(25,744 Views)

Here's a slighly simpler version (where epsilon is a small positive number):



Message Edited by altenbach on 07-08-2008 11:54 AM
0 Kudos
Message 10 of 14
(25,728 Views)