You are here:

C++/Positive value


Dear expertise,

Here is the sample of my calculation.

m_fnumber1 - m_fnumber2 = m_fresults;

The situation is like this.
i want the value of the calculation is in positive value.  That mean the "m_fnumber1 > mf_number2"

The question is how i want to get the positive value if "m_fnumber2 > m_fnumber1".

Is it in c++, i can use any simple function to make it work as i request?


opeye , Thank you for your question.

You may not get what you expect if you write a statement

m_fnumber1 - m_fnumber2 = m_fresults;

Instead, you should place the result variable on the left side of the assignment operator, like this:

m_fresults = m_fnumber1 - m_fnumber2;

If you want the absolute value of the result, you can calculate it like this:

m_fresults = m_fnumber1 - m_fnumber2;
if (m_fresults < 0)
  m_fresults = - m_fresults;

David Spector


All Answers

Answers by Expert:

Ask Experts


David Spector


Highly knowledgeable in the C++ language, Visual C++ (MSVC), Windows API, documentation and other quality-assurance techniques, and debugging. Knowledgeable in MFC, COM, GUI design, and object-oriented design.


I have been a software engineer since 1965. I have been published. My specializations have been: biomedical programming, compiler implementation, and many kinds of Windows programming. I don't do Databases or other business-oriented stuff.

Windows?/DOS Developer's Journal, ACM SIGPLAN Notices, and Computer Science Press.

ICCP Systems Programming Certification
Master's degree equivalent in Computer Science

©2016 All rights reserved.