Created
September 7, 2016 16:01
-
-
Save flyte/a0d3b029fbd01c2fdf6300d6c9ea46b5 to your computer and use it in GitHub Desktop.
Percentage Change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from decimal import Decimal | |
def percentage_change(old_value, new_value): | |
""" | |
Accepts two integers, an old and a new number, | |
and then measures the percent change between them. | |
""" | |
change = abs(new_value - old_value) | |
try: | |
pct_change = (change / Decimal(old_value)) | |
return pct_change*100 | |
except ZeroDivisionError: | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment