Click here to Skip to main content
15,888,226 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hai,
I have unsigned char value nad i need to convert it to a double value. How can I convert it???

Please help....
Posted
Comments
Sergey Alexandrovich Kryukov 21-Mar-12 18:44pm    
And what it supposed to mean when presented as double? Why? just to waste 8 bytes instead of one? I don't see any sense...
--SA

you can simply assign the unsigned char value to a variable of type double as shown below

unsigned char ch = 'C';
double d = ch;

if you are so particular about using c++ style typecasting use static_cast as below

C++
double d = static_cast<double>( ch );</double>
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 21-Mar-12 18:46pm    
I never understood why answering questions which seem to have no sense, even "correctly"...
--SA
Just assign it:
C++
unsigned char u = 150;
double d = u;
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 21-Mar-12 18:46pm    
I never understood why answering questions which seem to have no sense, even "correctly"...
--SA
CPallini 22-Mar-12 4:26am    
Because
I am not aware it is a nonsense.
Moreover, the OP
(1) May actually need it (e.g. he/she needs to pass a value to a function requiring the double - e.g. pow(u, u) wouldn't compile).
(2) Looks a bit confused (that is give him/her a hook).
:-)
Sergey Alexandrovich Kryukov 22-Mar-12 16:00pm    
I can see your point...
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900