1234567891011121314151617181920212223 |
- # -*- coding: utf-8 -*-
- # !/usr/bin/env python
- from decimal import Decimal, ROUND_HALF_UP
- def force_decimal(amount):
- """Given an amount of unknown type, type cast it to be a Decimal."""
- if not isinstance(amount, Decimal):
- return Decimal(str(amount))
- return amount
- def quantize(decimal_value, places = '0.01'):
- # type:(Decimal, str)->Decimal
- return decimal_value.quantize(Decimal(places), rounding = ROUND_HALF_UP)
- class UnitBase(object):
- @classmethod
- def initial(cls, default = '0'):
- return cls(default)
|