formating the variables in a dialog box

How do I make the values appearing in the dialog box for variables dlg.m_edit3 and dlg.m_edit4 show only upto 3 significant variables inside of more than 5-6 significant variables it is now showing (the code is shown below) ... What do I need to change in the code below ...

Thanks




// ******
 void CRms_VoltageView::OnLButtonUp(UINT nFlags, CPoint point)
 {
      // TODO: Add your message  handler code here and/or call default
      
     // Dialog Box No. 2
      CdlgDialog2 dlg;

      if (m_bDraw)
      {
// ??????????? this is where the
// problem is ?????????????

dlg.m_edit3 = (float)pline_array[current_line].fin_volt;
dlg.m_edit4 = (float)pline_array[current_line].fin_time;

if (dlg.DoModal() == IDOK)
            {            
                 .....
                }
arindam042099Asked:
Who is Participating?
 
chensuConnect With a Mentor Commented:
Associate the edit controls with CString member variables instead of float member variables, which I guess you are currently using. Thus, you can call the CString::Format as follows.

dlg.m_edit3.Format(_T("%.3f"), pline_array[current_line].fin_volt);
dlg.m_edit4.Format(_T("%.3f"), pline_array[current_line].fin_time);
0
 
arindam042099Author Commented:
Thanks
Once the values that are in pline_array[current_line].fin_volt and pline_array[current_line].fin_time are assigned to dlg.m_edit3,dlg.m_edit4 I want to change that (shown in the code) and then use then variables (will now need them to be in float) for calculations,... How can I convert them here to floats ???

 m_Setvolt = dlg.m_edit3;
 m_Tracetime =(float) ((int)((dlg.m_edit4/Half_Period)+(float) 0.5)* Half_Period);    
0
 
chensuCommented:
You may use the C Run-time Library functions _tcstod(strtod, wcstod) to convert strings to a double-precision value.
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
arindam042099Author Commented:
can I use atof also .... what will be the difference between the two .. does atof convert CString member variables

THANKS
0
 
arindam042099Author Commented:
why is it I cannot format a float member variables to show 3 significant digits when my dialog box pops up ... and is so what is the code to do that ..
thanks
0
 
chensuCommented:
atof does it as well. The only difference is that strtod returns a pointer to character that stops scan.

I don't understand your last comment.
0
 
arindam042099Author Commented:
What I meant was why convert to string and then convert from string to float .. why cannot I use float all the way and only use formating to display into the dialog box ...
0
 
chensuCommented:
Because an edit control accepts strings only and there is no function to format a float number into an edit control.
0
 
arindam042099Author Commented:
thanks
0
All Courses

From novice to tech pro — start learning today.