| | |
Basic doubt
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2006
Posts: 78
Reputation:
Solved Threads: 0
I'm doing a dialog application in C++ to calculate something, but I want the result to be with 2 decimal number, how to do this?
here is the function:
I want the variable m_total to show with 2 decimal numbers, like, p.e. x,yz.
Thanks
here is the function:
C++ Syntax (Toggle Plain Text)
void CCalculatorDlg::Oncalc() { // TODO: Add your control notification handler code here UpdateData(TRUE); if ((m_amostras >= 1) && (m_elementos >= 1) && (m_click == true)) { if (m_interno) m_total = (19.8522+(3.99038*(m_elementos-1))+((1.74579+((m_elementos-1)*0.1496))*(m_amostras-1))) + (2.5*m_preparacao); else if (m_externo) { if (m_amostras < 11) m_total = (19.9519+(19.9519*(m_elementos-1))+((19.9519+((m_elementos-1)*2.494))*(m_amostras-1)))+(5*m_preparacao); if (m_amostras > 10) m_total = (19.9519+(19.9519*(m_elementos-1))+(((19.9519+((m_elementos-1)*2.494))*(9))+((9.98+((m_elementos-1)*2.494))*(m_amostras-10))))+(5*m_preparacao); } } else { if ((m_amostras < 1) || (m_elementos < 1)) MessageBox("Tem que especificar pelo menos uma amostra e um elemento!"); if (!m_click) MessageBox("Tem que especificar o tipo de cliente!"); } UpdateData(FALSE); }
I want the variable m_total to show with 2 decimal numbers, like, p.e. x,yz.
Thanks
Look in setprecision manipulator
The key to eliminating bugs from your code is learning from your mistakes.
•
•
Join Date: Mar 2006
Posts: 78
Reputation:
Solved Threads: 0
But I'm not using cout... The variable m_total is shown at the dialog box in an edit box...
Last edited by gampalu; Sep 15th, 2006 at 8:13 am.
you will have to format the string before it is displayed in the dialog box. If you are using MFC, then use CString's Format() method, for exaple
If you are not using MFC, then use standard C sprintf() function
C++ Syntax (Toggle Plain Text)
CString text; float number = 12.123456; text.Format("%.2f", number); GetDialogItem(IDC_EDI1)->SetWindowText(text);
If you are not using MFC, then use standard C sprintf() function
C++ Syntax (Toggle Plain Text)
char text[20]; float number = 12.123456; sprintf(text,"%.2f", number); GetDialogItem(IDC_EDI1)->SetWindowText(text);
•
•
Join Date: Mar 2006
Posts: 78
Reputation:
Solved Threads: 0
I'm using MFC and I tried your exmeple but I get this:
Can you figure out why?
thanks
C++ Syntax (Toggle Plain Text)
--------------------Configuration: calculator - Win32 Release-------------------- Compiling... calculatorDlg.cpp D:\vários\mail\calculator\calculatorDlg.cpp(201) : error C2065: 'GetDialogItem' : undeclared identifier D:\vários\mail\calculator\calculatorDlg.cpp(201) : error C2227: left of '->SetWindowTextA' must point to class/struct/union Error executing cl.exe. calculator.exe - 2 error(s), 0 warning(s)
Can you figure out why?thanks
Sorry about the mistake. Should have been GetDlgItem
Alternatively, if you used ClassWizard to assign a CString variable to the edit control, then you don't need to call GetDlgItem() but use that variable instead, then call UpdateData(FALSE) to update the edit control.
If you are new to MFC and you are using VC++ 6.0 compiler you might want to read the Microsoft Scribble tutorial, which will show you how to do all that neat stuff.
Alternatively, if you used ClassWizard to assign a CString variable to the edit control, then you don't need to call GetDlgItem() but use that variable instead, then call UpdateData(FALSE) to update the edit control.
If you are new to MFC and you are using VC++ 6.0 compiler you might want to read the Microsoft Scribble tutorial, which will show you how to do all that neat stuff.
•
•
Join Date: Mar 2006
Posts: 78
Reputation:
Solved Threads: 0
•
•
•
•
Sorry about the mistake. Should have been GetDlgItem
Alternatively, if you used ClassWizard to assign a CString variable to the edit control, then you don't need to call GetDlgItem() but use that variable instead, then call UpdateData(FALSE) to update the edit control.

thanks for your attention.
•
•
•
•
If you are new to MFC and you are using VC++ 6.0 compiler you might want to read the Microsoft Scribble tutorial, which will show you how to do all that neat stuff.
thanks again
![]() |
Similar Threads
- Image read and write operations in turbo C (C)
- Basic C Question (C)
- Doubt about compiling. (Legacy and Other Languages)
Other Threads in the C++ Forum
- Previous Thread: Need help,my C++ calc
- Next Thread: A function which will transfer the data from a file to STL( vector or map) object.
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






