Click to See Complete Forum and Search --> : Convert double to *chart


wakeup
10-26-2005, 04:50 AM
I want convert double to char * string for insert in a .ini file

char mystring[50];
double mydouble;

sprintf(mystring, "%f", mydouble);

It runs ok, but when I have a very small double (for example
0.000000000000000000000000001)
It convert to 0.00000000 (=0) and not to 1.0e-20
Do you know how solve it?
Thanks

_______________________
Hip Hop Directo (http://www.hhdirecto.net)
Foros de musica (http://forosunidos.webcindario.com)

Danny
10-26-2005, 09:49 AM
try to specify higher precision, say "%30.28f" which means 30 digits, 28 of which are for the fraction.

wakeup
10-26-2005, 10:02 AM
Thanks it is better but, I would like it puts something as 1.3e-20, is this posible?
Thankss

Danny
10-26-2005, 10:23 AM
yes, use the %e or %E format flags instead of %f.

wakeup
10-26-2005, 10:24 AM
This is the solucion "%e" in cientific mode
Thanks

Danny
10-26-2005, 02:40 PM
btw, you want to initialize your buffer before using it:

char mystring[50] = {0};
...