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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Double <-> *char (Hex) 1

Status
Not open for further replies.

chpicker

Programmer
Apr 10, 2001
1,316
I work mainly with Visual FoxPro which is a VERY high-level language. I am familiar (I use the term loosely) with the structure of C/C++, but I just can't for the life of me figure out how to program for Windows. *sigh*

In any case, I have a need to convert 64-bit doubles stored in a data file to their decimal equivalents and back. While I've had great luck using UNIONs to combine a double with an __int64 and using printf(), this only gives the illusion of conversion. Using this method, I was able to construct a data file by hand by hard-coding the numbers to convert. I can't do them by hand anymore.

I need to create two functions: one that will take a DOUBLE and return a hex string as a *char, and one that will take a *char (8 2-character bytes+null terminator, total length 17) and return the DOUBLE that it represents. Any suggestions?

Ian
 
char buffer[30];
double X;
_gcvt( X, 14, buffer ); //In buffer You have Your string
double Y = atof(buffer ); //You have Your double in Y now

 
Thanks...that points me in the right direction!

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top