Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

CDialog Class Member Variable precision

How do I set the precision for the variables.  Similar to iostream.setprecision, Fortran "FIX" etc.  I would like not to convert back and forth between types.  Can't find this info in my books or the CD-ROM online help.  Thanks for any help in this "simple" matter.
0
lucie
Asked:
lucie
  • 2
1 Solution
 
shaigCommented:
I don't understand what do CDialog members have to do with precision, and if they do, could you be more presice?

Anyway this is probably a C/C++ question:
the copnversion between types in C is automatic.
It is possible to set the precision when:
a) printing - sprintf or CString::Format.  example:
  sprintf( buffer, "The float value is: %8.2f", m_floatVarible );
b) inputing - scanf(), very simulare.

hope i helped.  : - {}
0
 
lucieAuthor Commented:
VC++ uses DDX/DDV to exchange data between the Dialog Control and the Member Variable.  In context:

m_floatVariable = sqrt(some_value);

When variable data sent back to the Dialog Control, the Dialog Box displays a number like 4.23592347575, when I'd like to see a number 4.24 or 4.236.  I've found that I can accomplish this by changing the type from "double" using the _fcvt function which allows you to control the # of digits after the decimal.  I'd just like to control rounding of the variable without changing types.  In fortran, I'd just FIX 2 or 3 and be done with it.  Just want to know if you can do this in VC++
0
 
RONSLOWCommented:
Write your own DDX routine (copy the MFC version or at least call it) and do your percision fixes there.

something like this ...

void AFXAPI DDX_Text_2DP(CDataExchange* pDX, int nIDC, float& value)
{
      if (pDX->m_bSaveAndValidate) {
            DDX_Text(pDC,nIDC,value);
      } else {
            CString buffer;
            HWND hWndCtrl = pDX->PrepareEditCtrl(nIDC);
            buffer.Format("%.2f", value);
            ::SetWindowText(hWndCtrl, szBuffer);
      }
}

0
 
lucieAuthor Commented:
Thanks verrrrrrry much.

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now