Skip to content

Instantly share code, notes, and snippets.

@flyte
Created September 7, 2016 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flyte/a0d3b029fbd01c2fdf6300d6c9ea46b5 to your computer and use it in GitHub Desktop.
Save flyte/a0d3b029fbd01c2fdf6300d6c9ea46b5 to your computer and use it in GitHub Desktop.
Percentage Change
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