c++ - Converting float to char
- Elisha Kendagor <kendagor iconnect.co.ke> Apr 06 2001
- Jan Knepper <jan digitalmars.com> Apr 06 2001
- Elisha Kendagor <kendagor iconnect.co.ke> Apr 06 2001
- Roland <rv ronetech.com> May 02 2001
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: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
Thanks !! It really Knepped it. Jan Knepper wrote: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: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
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 :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!
May 02 2001