Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

char representation of a double

Status
Not open for further replies.

senorbuckwheat

Programmer
Jul 12, 2002
17
US
Hi,

I am looking for a way to convert a double to the char representation, ie. put double, which is eight bytes, to char[8];
Example:

double nDb = 12.34;
char szDb[8];

szdB would hold the character representation of nDb which might look something like:
[0] 0''
[1] 0''
[2] 0''
[3] 0''
[4] 0''
[5] 0''
[6] 51'3'
[7] 64'@'

Thank you
 
Hi,
How about a union?

union dbltoch
{
double d;
unsigned char c[8];
};

Hope this helps. Pappy
You learn something everyday.
 
memcpy would be how I would approach it. But you could also just cast it. Just remember there can be null terminators in spots you dont want and it wont print out properly. Also, for safety, i would use char[9] and have element 8 set to zero.

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top