Skip to content

Instantly share code, notes, and snippets.

@kgriffs
Created October 17, 2018 23:06
Show Gist options
  • Save kgriffs/871a9176515b55d94a77c974efef1d2e to your computer and use it in GitHub Desktop.
Save kgriffs/871a9176515b55d94a77c974efef1d2e to your computer and use it in GitHub Desktop.
DB to Decimal Utility Functions
def _db_to_decimal(db_number):
if db_number is None:
return None
return Decimal(int(db_number)) / 100
def _decimal_to_db(decimal_number, currency=True):
if decimal_number is None:
return None
if currency:
decimal_number = decimal_number.quantize(Decimal('.01'), rounding=ROUND_CEILING)
return int(decimal_number * 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment