shouldnt this return 100 as the percentage is of 100% difference

0

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

(secondNumber - firstNumber)*100.0/firstNumber
is one kind of percentage difference
(secondNumber - firstNumber)*100.0/secondNumber
is another
(secondNumber - firstNumber)*200.0/(firstNumber+secondNumber)
is a more symmetric kind of difference
abs(secondNumber - firstNumber)*100.0/max(abs(firstNumber),abs(secondNumber))
may be an appropriate kind of percentage difference in other cases
What is the application of this function?

0

Wanting2LearnManAuthor Commented:

re: What is the application of this function?
This function will accept a number and return that same number increased or decreased by a certain percentage.

re: shouldnt this return 100 as the percentage is of 100% difference.
If any of the numbers are 0 I want to ignore the result.

This function will accept a number and return that same number increased or decreased by a certain percentage.

That sounds like the opposite of what CalculatePercentageDifference does
What you describe sounds like it would take firstNumber and percentDiff as parameters and return secondNumber as a result.

If any of the numbers are 0 I want to ignore the result.

does that mean that
CalculatePercentageDifference(100,99)
CalculatePercentageDifference(100,0)
CalculatePercentageDifference(0,99)
are all considered equivalent?

Don't forget that there will be two different answers. The percentage that a smaller number is less than a larger number is not the same as the percentage that a larger number is greater than a smaller number.

If you have two numbers - 95 and 100 - 95 is 5 percent less than 100 - but 100 is not 5 percent greater than 95. It is 5.263 percent greater.

Hi there,
The webpage you have as reference indicates that you followed almost the right way...
One small addition in case of dividing by zero error or other errors:
1. As the webpage says the difference will be good to report a double value...
2. In case of error it will be better to have a boolean return value.