|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
c++ - Converting float to char
I have a real number.... float r and I want to store it into char floatstr[6] How do I get to do it? Or: Do you know how I can display a real number using DrawText, TextOut, SetDlgItemText.... etc? Please reply soon! Apr 06 2001
I would use double instead of float.
Use: double d;
TCHAR str [ 32 ];
_stprintf ( str, "%.2f", d );
Or check into the ecvt, fcvt, gcvt function in stdlib.h
Don't worry, be Kneppie!
Jan
Elisha Kendagor wrote:
Apr 06 2001
Thanks !! It really Knepped it. Jan Knepper wrote: Apr 06 2001
below a way to make a string with a double
char* str_double(char* s, const double d, const int prec, const char mod) {
//prec=nb chiffres apres le . decimal, 0 -> 6
//mod='f,'e/E','g/G'
//f -> format decimal: [-]dd.dddd
//e/E -> format scientifique: [-]d.dddd e/E+-dd
//g/G -> f si precision suffisante, e/E sinon
//return s
char format[16];
strcpy(format,"%-.");
format[3]=(prec==0) ? '6' : '0'+prec;
format[4]=mod;
format[5]=0;
sprintf(s,format,d);
return s;
}
Roland
Elisha Kendagor a écrit :
May 02 2001
|