CString
-
I have this : CString sEx; m_ex.GetWindowText(sEx); m_ex = CEdit ; i whant somethig like that : 16.0697 to 16.0700 !!!!!!!! round! How????? Please someoane help me !!!! (visual c++)
Bravoone
-
I have this : CString sEx; m_ex.GetWindowText(sEx); m_ex = CEdit ; i whant somethig like that : 16.0697 to 16.0700 !!!!!!!! round! How????? Please someoane help me !!!! (visual c++)
Bravoone
-
Try this function:
void RoundString(CString& str) { float fVal = 0; swscanf_s(str, L"%f", &fVal); int nTemp = (int)((fVal + 0.005)*100); fVal = (float)((float)nTemp/100); str.Format(L"%.4f", fVal); }
i dont understand , can you explain me on my example ? thank you ! so mutch !
Bravoone
-
i dont understand , can you explain me on my example ? thank you ! so mutch !
Bravoone
Bravoone_2006 wrote:
can you explain me on my example ?
He gave you an example! :rolleyes:
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
i dont understand , can you explain me on my example ? thank you ! so mutch !
Bravoone
-
Bravoone_2006 wrote:
can you explain me on my example ?
He gave you an example! :rolleyes:
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
i need something more simple, its not exist something more simple then this? thank you !
Bravoone
-
The function I gave you receives a CString object by reference, puts the value into a float variable, rounds it to 2 numbers after the decimal point and converts the new (rounded) value back into the CString object.
i need something more simple, its not exist something more simple then this? thank you !
Bravoone
-
i need something more simple, its not exist something more simple then this? thank you !
Bravoone
-
i need something more simple, its not exist something more simple then this? thank you !
Bravoone
Bravoone_2006 wrote:
its not exist something more simple then this?
no.
Maximilien Lincourt Your Head A Splode - Strong Bad
-
i need something more simple, its not exist something more simple then this? thank you !
Bravoone
More simple than a copy/paste ?? :confused:
Cédric Moonen Software developer
Charting control [v1.2 - Updated] -
More simple than a copy/paste ?? :confused:
Cédric Moonen Software developer
Charting control [v1.2 - Updated]That's two operations, Cedric. Can't you trim it down to one? Quit making folks work so hard.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
i need something more simple, its not exist something more simple then this? thank you !
Bravoone
you idiot. someone gives you a function you just have top copy/paste in your code and call, but always you complain. :suss:
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
That's two operations, Cedric. Can't you trim it down to one? Quit making folks work so hard.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
copy/paste == 2 ...processing reduction... shoot in the ass == 1 reduction performed successfully :jig:
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
Try this function:
void RoundString(CString& str) { float fVal = 0; swscanf_s(str, L"%f", &fVal); int nTemp = (int)((fVal + 0.005)*100); fVal = (float)((float)nTemp/100); str.Format(L"%.4f", fVal); }
your example will compile only if UNICODE is defined... you should use
_T()
,stscanf()
and so on...
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
your example will compile only if UNICODE is defined... you should use
_T()
,stscanf()
and so on...
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
ok ! i understand you but you don t understand ME ! Le t say if someoane say : " You are not so smart if you use 6 lines of code for this ! " All i want is to find a way to make this function more simple , because he use to mutch code for this function ! for this function !? think about it its just ROUND ! make this : 16.0697 to 16.0700 to use sutch code!? the code is fine but no one say its wrong! i remind you i have CDialog base aplication, i have for ex: m_edit CEdit; m_edit2 CEdit; i must use for ex: OnChange m_edit; CString sT1,sT2; m_edit.GetWindowText(sT1); ... ... ... m_edit2.SetWindowText(sT2);
Bravoone
-
ok ! i understand you but you don t understand ME ! Le t say if someoane say : " You are not so smart if you use 6 lines of code for this ! " All i want is to find a way to make this function more simple , because he use to mutch code for this function ! for this function !? think about it its just ROUND ! make this : 16.0697 to 16.0700 to use sutch code!? the code is fine but no one say its wrong! i remind you i have CDialog base aplication, i have for ex: m_edit CEdit; m_edit2 CEdit; i must use for ex: OnChange m_edit; CString sT1,sT2; m_edit.GetWindowText(sT1); ... ... ... m_edit2.SetWindowText(sT2);
Bravoone
It is almost certainly possible to write your function in one line - but the advice that you are getting from professional programmers here is not to do that. What it does will be the same, the syntax just more complex. If this is not simple enough for you, find a better way. Before you complain about the solution someone has bothered to give you, engage brain and think of what is involved (having one solution in front of you should help). In this case the simplest way I can see to round the contents of one edit box is to get the string, convert to a floating point representation, round and convert back to a string. If you can find a better way, we have shared one solution with you, please share yours with us.
Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
-
your example will compile only if UNICODE is defined... you should use
_T()
,stscanf()
and so on...
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]