0
How can I turn an integer to double
Use static cast
2 ответов
+ 4
C++ is a statically typed languages. The datatype is fixed when the variable is declared.
But you can convert using what the programmer calls a 'union' , but I don't suggest you use those as they may create problems.
You can just make a new variable with a datatype of double and make it take the value of the integer variable.
+ 1
Hey buddy ,
Buddy you can use simple casting type, static_cast
static _cast can be used to convert one type into another, but should not be used for to cast away const-ness or to cast between non-pointer and pointer types.
static casts are prepared over c-style casts when they are available because they are both more restrictive and more noticeable
systax:
static_cast <type> (value or expression);
to convert int to double iassume the following declaration for example
int number ;
static_cast <double>(number )
Hope you understood