CONVERTING double TO char*

  • Thread starter Thread starter LUIS FAJARDO
  • Start date Start date
L

LUIS FAJARDO

How can I convert from a double variable to string using
standard ANSI-C.


Thanks


PS: I'm currently using _fcvt but is not enough.
 
Hi Luis,

Thanks for your post. I suggest you to check out the funciton sprintf().
For example:

double source = 3.14159;
char destiny[100];
sprintf(destiny, "%e", source);
//Result:
//destiny = "3.141590e+000"

For more information on sprintf and its format string, please refer to the
following MSDN documentation:

sprintf, swprintf
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/
_crt_sprintf.2c_.swprintf.asp?frame=true

Format Specification Fields: printf and wprintf Functions
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/
_crt_format_specification_fields_.2d_.printf_and_wprintf_functions.asp?frame
=true

printf Type Field Characters
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/
_crt_printf_type_field_characters.asp

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Tian said:
Hi Luis,

Thanks for your post. I suggest you to check out the funciton sprintf().
For example:

double source = 3.14159;
char destiny[100];
sprintf(destiny, "%e", source);
//Result:
//destiny = "3.141590e+000"

For more information on sprintf and its format string, please refer to the
following MSDN documentation:

sprintf, swprintf
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/
_crt_sprintf.2c_.swprintf.asp?frame=true

Format Specification Fields: printf and wprintf Functions
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/
_crt_format_specification_fields_.2d_.printf_and_wprintf_functions.asp?frame
=true

printf Type Field Characters
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/
_crt_printf_type_field_characters.asp

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Or.. if you are not averse to using STL, you should be able to use
strstream class and pump that double into it.. When you get the str()
out of it.. it will have double as "string" in it..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top