LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Double and Int

Solved!
Go to solution
Is there a proper way to do a math operation on 2 int declared intergers that is known should return a double or a floating point variable? I have an operation on 2 ints
 
int Adaptive_Gain_value
int Adj_Gain_value
double results
 
// to get or perscribe a percentage of the Adaptive_Gain_value... lets to the get the Percentage first.
 results = Adj_Gain_value / Adaptive_Gain_value;
 
// this always returns a 0.000000000
// int the past, I thought this should work without having to change the declaration, or do I need to do some special cast?
 
Thanks!
ChipB
 


Message Edited by ASIC IIBU Tech on 05-07-2008 04:31 PM
0 Kudos
Message 1 of 4
(4,047 Views)
Solution
Accepted by topic author ASIC_LabRat
Dividing two ints will always result in an int and 'chop' off the floating point part.  You're on the right track with your cast....

results = (double)adj_gain_value / (double)adaptive_gain_value


0 Kudos
Message 2 of 4
(4,041 Views)
I think you only need to cast one of the ints to double, the compiler wil promote everything else  in the expression to match.

Stroustrop says most casts are evidence of a design error 🙂

Menchar
0 Kudos
Message 3 of 4
(4,008 Views)

HA!

you guys are TOO funny... thanks, the cast system works in this instance.... 🙂

0 Kudos
Message 4 of 4
(4,006 Views)