T O P I C R E V I E W |
Rimmer |
Posted - 11/15/2003 : 05:15:05 AM Sorry for the extremely basic question, but I have two ints x1 and x2 and a double scalex. However when I write
scalex = x1 / x2
the result in scalex is always an integer and not the double that I require.
Why do I have this behaviour?
Thanks
Mick |
3 L A T E S T R E P L I E S (Newest First) |
cpyang |
Posted - 11/15/2003 : 4:35:01 PM That is how it is in C/C++, when doing arithmetics between integers, then the result is also must be an integer, so must cast at least one value into double so that the arithmetics will result into double.
CP
|
Rimmer |
Posted - 11/15/2003 : 1:16:11 PM Thanks that worked
Seems strange to have to cast in such a simple case
Mick |
Mike Buess |
Posted - 11/15/2003 : 09:11:02 AM Hi Mick,
Try this...
scalex = (double) x1 / x2;
Mike Buess Origin WebRing Member |