www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.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++ - Problem: Real numbers

↑ ↓ ← Elisha Kendagor <kendagor iconnect.co.ke> writes:
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.
Apr 08 2001
↑ ↓ "Rajiv Bhagwat" <dataflow vsnl.com> writes:
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.

Apr 10 2001
↑ ↓ Jan Knepper <jan smartsoft.cc> writes:
 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
Apr 10 2001
↑ ↓ "Rajiv Bhagwat" <dataflow vsnl.com> writes:
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

 )
 {
     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

 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

Apr 10 2001
↑ ↓ Jan Knepper <jan smartsoft.cc> writes:
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
Apr 11 2001
↑ ↓ "Kar Gay Lim" <kagay kimay.net> writes:
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.
Apr 11 2001
↑ ↓ Jan Knepper <jan smartsoft.cc> writes:
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
Apr 11 2001
↑ ↓ → Elisha Kendagor <kendagor iconnect.co.ke> writes:
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

Apr 13 2001