Thread overview | ||||||
---|---|---|---|---|---|---|
|
April 06, 2001 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! |
April 06, 2001 Re: Converting float to char | ||||
---|---|---|---|---|
| ||||
Posted in reply to Elisha Kendagor | 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!
|
April 06, 2001 Re: Converting float to char | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jan Knepper | 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!
|
May 02, 2001 Re: Converting float to char | ||||
---|---|---|---|---|
| ||||
Posted in reply to Elisha Kendagor | 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!
|
Copyright © 1999-2021 by the D Language Foundation