Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
April 08, 2001 Problem: Real numbers | ||||
---|---|---|---|---|
| ||||
char *dispstr; int ddec, dsign; double immservice; . . //suppose immservice = 832.3343 and I convert it... dispstr = _fcvt(immservice, 5, &ddec, &dsign); //I will get dispstr = 8323345, ddec = 3; dsign = 0; // please guide me to obtain something to fit here... SetDlgItemText(hdlg,ID_TIMEQUEUE, ****** ); //...so that the displayed text is "832.3345" Thank you. |
April 10, 2001 Re: Problem: Real numbers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Elisha Kendagor | The sprintf function is an easier way of doing this. Use of --------------- char str[30]; sprintf(str, "%7.3f", immservice); SetDlgItemText(hdlg,ID_TIMEQUEUE, str ); ---------------- should do the trick. If you are using C++ (and why not? it is better!) why not define a class that does the following: (Based on the code above)(This is an excersize for you!) ----------------- FloatText ft(hdlg, ID_TIMEQUEUE); ft = immservice; ----------------- This will be quite useful if you need to do it often. - Rajiv Elisha Kendagor <kendagor@iconnect.co.ke> wrote in message news:3AD0BA05.1DDC8AF4@iconnect.co.ke... > char *dispstr; > int ddec, dsign; > double immservice; > . > . > file://suppose immservice = 832.3343 and I convert it... > dispstr = _fcvt(immservice, 5, &ddec, &dsign); > > file://I will get dispstr = 8323345, ddec = 3; dsign = 0; // please guide me to obtain something to fit here... SetDlgItemText(hdlg,ID_TIMEQUEUE, ****** ); > > file://...so that the displayed text is "832.3345" > > Thank you. > > |
April 10, 2001 Re: Problem: Real numbers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rajiv Bhagwat | > FloatText ft(hdlg, ID_TIMEQUEUE);
> ft = immservice;
Nag!
A function will do just fine...
static const int BUFFER = 256;
BOOL SetDlgItemDouble ( HWND hwnd, int item, LPCTSTR format, double value
)
{
TCHAR buffer [ BUFFER ];
_stprintf ( buffer, format, value );
return ( SetDlgItemText ( hwnd, item, buffer ) );
}
Probably even more sufficient... (Just from the top of my head...)
static const int BUFFER = 1024; // Make sure this is long enough!
int PrintDlgItem ( HWND hwnd, int item, LPCTSTR format, ... )
{
TCHAR buffer [ BUFFER ];
va_list arg;
va_start ( arg, format );
_vstprintf ( buffer, format, arg );
va_end ( arg );
return ( SetDlgItemText ( hwnd, item, buffer ) );
}
That you can just...
PrintDlgItem ( hDlg, IDC_WHATEVER, "%8.2f", immservice );
PrintDlgItem ( hDlg, IDC_ANOTHER , "%.2f", immservice );
Jan
|
April 11, 2001 Re: Problem: Real numbers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jan Knepper | Sorry, if that felt like a nag. You are right, a function will do. I thought of a class with overloaded assignment operators for printing ints and doubles and even user defined types, but overloaded functions can do these as well. Rajiv Jan Knepper <jan@smartsoft.cc> wrote in message news:3AD33A0D.3B073D50@smartsoft.cc... > > FloatText ft(hdlg, ID_TIMEQUEUE); > > ft = immservice; > > Nag! > A function will do just fine... > > static const int BUFFER = 256; > > > > BOOL SetDlgItemDouble ( HWND hwnd, int item, LPCTSTR format, double value > ) > { > TCHAR buffer [ BUFFER ]; > > _stprintf ( buffer, format, value ); > > return ( SetDlgItemText ( hwnd, item, buffer ) ); > } > > > > Probably even more sufficient... (Just from the top of my head...) > > static const int BUFFER = 1024; // Make sure this is long > enough! > > > > int PrintDlgItem ( HWND hwnd, int item, LPCTSTR format, ... ) > { > TCHAR buffer [ BUFFER ]; > va_list arg; > > va_start ( arg, format ); > _vstprintf ( buffer, format, arg ); > va_end ( arg ); > > return ( SetDlgItemText ( hwnd, item, buffer ) ); > } > > > That you can just... > > PrintDlgItem ( hDlg, IDC_WHATEVER, "%8.2f", immservice ); > PrintDlgItem ( hDlg, IDC_ANOTHER , "%.2f", immservice ); > > Jan > > |
April 11, 2001 Re: Problem: Real numbers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rajiv Bhagwat | Rajiv Bhagwat wrote:
> I thought
> of a class with overloaded assignment operators for printing ints and
> doubles and even user defined types.
Makes sense.
I sometimes think that we have to be careful in C++ not to get overly
classified. <g>
(Isn't it kinda surprizing that functions like these are still not part of the
Windows API...)
Jan
|
April 11, 2001 Re: Problem: Real numbers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jan Knepper | Jan Knepper <jan@smartsoft.cc> wrote in message news:3AD4ADFF.2764579F@smartsoft.cc... > Rajiv Bhagwat wrote: > > > I thought > > of a class with overloaded assignment operators for printing ints and > > doubles and even user defined types. > > Makes sense. > I sometimes think that we have to be careful in C++ not to get overly > classified. <g> > (Isn't it kinda surprizing that functions like these are still not part of the > Windows API...) Hmmmmmm,.... but if you use MFC/ATL, it is automatically generated by the ClassWizards. |
April 11, 2001 Re: Problem: Real numbers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kar Gay Lim | Kar Gay Lim wrote:
> > (Isn't it kinda surprizing that functions like these are still not part of the
> > Windows API...)
>
> Hmmmmmm,.... but if you use MFC/ATL, it is automatically generated by the ClassWizards.
What do you mean generated???
The usage of :: DataExchange ( CDataExchange * ) and the DDX_* functions?
I use MFC a lot actually, but hardly every any of that stuff!
Jan
|
April 13, 2001 Re: Problem: Real numbers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jan Knepper | Hey all,
Thanks a lot for your help.
It really Knepped it!
Jan Knepper wrote:
> Kar Gay Lim wrote:
>
> > > (Isn't it kinda surprizing that functions like these are still not part of the
> > > Windows API...)
> >
> > Hmmmmmm,.... but if you use MFC/ATL, it is automatically generated by the ClassWizards.
>
> What do you mean generated???
> The usage of :: DataExchange ( CDataExchange * ) and the DDX_* functions?
>
> I use MFC a lot actually, but hardly every any of that stuff!
>
> Jan
|
Copyright © 1999-2021 by the D Language Foundation