# How to convert an integer to double?

• 07-06-2005
salman86
How to convert an integer to double?
Hey guys,

I'm beginner, Can please someone tell me how to convert an integer into double.

Another general question: Can someone give me a link where i can find all the useful methods (library methods). For example, for java we can find all the different classes and methods on sun site. I found out that the online tutorials are not that helpful.

I would really aperciate the help . Please someone? Thanks in advance!!
• 07-06-2005
JoshR
Assume the following decleration for each example:
Code:

`int number;`
Here are a couple of ways...
Code:

`double(number);`
Code:

`static_cast<double>(number);`
• 07-06-2005
salman86
Thanks Josh ... It worked
• 07-07-2005
sigfriedmcwild
Quote:

Originally Posted by JoshR
Code:

`double(number);`

You mean of course
Code:

`(double)number;`
• 07-07-2005
laserlight
double(number) also works - it uses a constructor, from what I understand.
• 07-07-2005
Daved
No need for a cast at all, the conversion is implicit. Just assign the int to the double.
• 07-07-2005
LuckY
Quote:

Originally Posted by laserlight
double(number) also works - it uses a constructor, from what I understand.

In C, only (double)value works, but the double(value) syntax became legal in C++ to allow primitive casting to appear like a function call. (No, it's not a constructor.)
• 07-07-2005
JoshR
Quote:

Originally Posted by Daved
No need for a cast at all, the conversion is implicit. Just assign the int to the double.

Who said he was assigning it to something? maybe he wanted to do calculations with it and print it.
• 07-07-2005
major_small
I was originally taught to use double(number), then I found out about other ways and now either use static_cast<double>(number) or (double)number...