C++: int to a double?

jguy100

Prince
Joined
Apr 3, 2003
Messages
471
Quick question for those who know C++:
Is there a quick way to convert an int to a double?
Thanks.
 
(double)our_int_value

should turn that into a double.
 
if "a" is an int and you want "b" to be the double, then try "b = a * 1.0;" . But i'm not really sure what you mean, or if that works.
 
Mise said:
if "a" is an int and you want "b" to be the double, then try "b = a * 1.0;" . But i'm not really sure what you mean, or if that works.
That is compiler-dependent. (Python is fun, I know :D )

Type conversion operators are the sure way to go.

Edit:
As an excercise, do the following:
float a = 3.76, b = 2.32;
int c

Try to output:
1. a mod b
2. a/b
3. a - converted to int / b and the result converted to int
4. attribute c the values of a + b, then print c as if it were a float so that in our case a+b == c
 
Back
Top Bottom