Solved

CDialog Class Member Variable precision

Posted on 1997-10-17
4
222 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now