Skip to content

Commit

Permalink
Merge branch 'coverage' into 389-forwardlooking-checks
Browse files Browse the repository at this point in the history
  • Loading branch information
dalepotter committed May 5, 2016
2 parents 2599210 + c318aa7 commit f4cbd0a
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 69 deletions.
18 changes: 16 additions & 2 deletions helpers/currency_conversion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,25 @@


def get_USD_value(input_currency, input_value, year):
""" Returns a USD value based on an inputted ISO currency, an inputted value and a year """
"""Returns a USD value based on an inputted ISO currency, an inputted value and a year
Inputs:
input_currency -- ISO currency code for the input currency
input_value -- Currency value
year -- year, as a string or integer
Returns:
Decimal of the USD value. Can be a negative value
"""

# Attempt to make a USD conversion
try:
usd_value = (1 / currency_values[input_currency][int(year)]) * float(input_value)
except KeyError:
# Arises if the currency is not in the sheet
usd_value = 0
except ZeroDivisionError:
# Arises if there is no data for the given year - i.e. set as zero for that year
usd_value = 0

return Decimal(usd_value) if usd_value > 0 else 0
# Cast to Decimal and return result
return Decimal(usd_value)
Loading

0 comments on commit f4cbd0a

Please sign in to comment.