Solved

CDialog Class Member Variable precision

Posted on 1997-10-17
4
242 Views
Last Modified: 2013-11-20
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
Comment
Question by:lucie
  • 2
4 Comments
 
LVL 3

Expert Comment

by:shaig
ID: 1308360
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
 

Author Comment

by:lucie
ID: 1308361
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
 
LVL 10

Accepted Solution

by:
RONSLOW earned 50 total points
ID: 1308362
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
 

Author Comment

by:lucie
ID: 1308363
Thanks verrrrrrry much.

0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question