当前位置: 首页>>代码示例>>Python>>正文


Python decimal.ROUND_UP属性代码示例

本文整理汇总了Python中decimal.ROUND_UP属性的典型用法代码示例。如果您正苦于以下问题:Python decimal.ROUND_UP属性的具体用法?Python decimal.ROUND_UP怎么用?Python decimal.ROUND_UP使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在decimal的用法示例。


在下文中一共展示了decimal.ROUND_UP属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_UP [as 别名]
def get(self):
        setting = db_session.query(DBSetting).get('credit-payoff')
        if setting is None:
            pymt_settings_json = json.dumps({'increases': [], 'onetimes': []})
        else:
            pymt_settings_json = setting.value
        pymt_settings_kwargs = self._payment_settings_dict(pymt_settings_json)
        try:
            ih = InterestHelper(db_session, **pymt_settings_kwargs)
            mps = sum(ih.min_payments.values())
            payoffs = self._payoffs_list(ih)
        except NoInterestChargedError as ex:
            resp = render_template(
                'credit-payoffs-no-interest-error.html',
                acct_name=ex.account.name,
                acct_id=ex.account.id
            )
            return resp, 500
        return render_template(
            'credit-payoffs.html',
            monthly_pymt_sum=mps.quantize(Decimal('.01'), rounding=ROUND_UP),
            payoffs=payoffs,
            pymt_settings_json=pymt_settings_json
        ) 
开发者ID:jantman,项目名称:biweeklybudget,代码行数:26,代码来源:credit_payoffs.py

示例2: calculate_price

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_UP [as 别名]
def calculate_price(base_quantity, quote_quantity, base_divisibility, quote_divisibility, order_type=None):
    if not base_divisibility:
        base_quantity *= config.UNIT
    if not quote_divisibility:
        quote_quantity *= config.UNIT

    try:
        if order_type == 'BUY':
            decimal.setcontext(decimal.Context(prec=8, rounding=decimal.ROUND_DOWN))
        elif order_type == 'SELL':
            decimal.setcontext(decimal.Context(prec=8, rounding=decimal.ROUND_UP))

        price = format(D(quote_quantity) / D(base_quantity), '.8f')

        decimal.setcontext(decimal.Context(prec=8, rounding=decimal.ROUND_HALF_EVEN))
        return price

    except Exception as e:
        logging.exception(e)
        decimal.setcontext(decimal.Context(prec=8, rounding=decimal.ROUND_HALF_EVEN))
        raise(e) 
开发者ID:CounterpartyXCP,项目名称:counterblock,代码行数:23,代码来源:dex.py

示例3: float2dec

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_UP [as 别名]
def float2dec(ft, decimal_digits):
    """
    Convert float (or int) to Decimal (rounding up) with the
    requested number of decimal digits.

    Arguments:
        ft (float, int): Number to convert
        decimal (int): Number of digits after decimal point

    Return:
        Decimal: Number converted to decima
    """
    with decimal.localcontext() as ctx:
        ctx.rounding = decimal.ROUND_UP
        places = decimal.Decimal(10)**(-decimal_digits)
        return decimal.Decimal.from_float(float(ft)).quantize(places)


# Sorting algos for rectangle lists 
开发者ID:secnot,项目名称:rectpack,代码行数:21,代码来源:packer.py

示例4: _get_depreciation_stop_date

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_UP [as 别名]
def _get_depreciation_stop_date(self, cr, uid, asset, depreciation_start_date, lost_year, context=None):
        if asset.method_time == 'year':
            depreciation_stop_date = depreciation_start_date + relativedelta(years=asset.method_number, days=-1)
        elif asset.method_time == 'number':
            if asset.method_period == 'month':
                depreciation_stop_date = depreciation_start_date + relativedelta(months=asset.method_number, days=-1)
            elif asset.method_period == 'quarter':
                depreciation_stop_date = depreciation_start_date + relativedelta(months=asset.method_number * 3, days=-1)
            elif asset.method_period == 'year':
                depreciation_stop_date = depreciation_start_date + relativedelta(years=asset.method_number, days=-1)
        elif asset.method_time == 'end':
            depreciation_stop_date = datetime.strptime(asset.method_end, '%Y-%m-%d')
        elif asset.method_time == 'percent':
            if asset.method_period == 'month':
                depreciation_stop_date = depreciation_start_date + relativedelta(
                    months=int(Decimal(str(100 / asset.method_number_percent)).quantize(Decimal('1'), rounding=ROUND_UP)), days=-1)
            elif asset.method_period == 'quarter':
                depreciation_stop_date = depreciation_start_date + relativedelta(
                    months=int(Decimal(str(100 / asset.method_number_percent * 3)).quantize(Decimal('1'), rounding=ROUND_UP)), days=-1)
            elif asset.method_period == 'year':
                depreciation_stop_date = depreciation_start_date + relativedelta(
                    years=int(Decimal(str(100 / asset.method_number_percent)).quantize(Decimal('1'), rounding=ROUND_UP)) + lost_year, days=-1)
        return depreciation_stop_date 
开发者ID:iw3hxn,项目名称:LibrERP,代码行数:25,代码来源:account_asset.py

示例5: roundup

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_UP [as 别名]
def roundup(number, num_digits = 0): # Excel reference: https://support.office.com/en-us/article/ROUNDUP-function-f8bc9b23-e795-47db-8703-db171d0c42a7

    if not is_number(number):
        return ExcelError('#VALUE!', '%s is not a number' % str(number))
    if not is_number(num_digits):
        return ExcelError('#VALUE!', '%s is not a number' % str(num_digits))

    number = float(number) # if you don't Spreadsheet.dump/load, you might end up with Long numbers, which Decimal doesn't accept

    if num_digits >= 0: # round to the right side of the point
        return float(Decimal(repr(number)).quantize(Decimal(repr(pow(10, -num_digits))), rounding=ROUND_UP))
        # see https://docs.python.org/2/library/functions.html#round
        # and https://gist.github.com/ejamesc/cedc886c5f36e2d075c5

    else:
        return ceil(number / pow(10, -num_digits)) * pow(10, -num_digits) 
开发者ID:vallettea,项目名称:koala,代码行数:18,代码来源:excellib.py

示例6: insert

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_UP [as 别名]
def insert(self, kwds):
        endedAt = int(kwds.get('endedAt', None))
        startedAt = int(kwds.get('startedAt', None))
        elapsed = Decimal(kwds.get('elapsed', None))
        if elapsed:
            elapsed = elapsed.quantize(Decimal('.0001'), rounding=ROUND_UP)
        args = json.dumps(list(kwds.get('args', ())))  # tuple -> list -> json
        kwargs = json.dumps(kwds.get('kwargs', ()))
        context = json.dumps(kwds.get('context', {}))
        method = kwds.get('method', None)
        name = kwds.get('name', None)

        session = sessionmaker(self.db)()
        session.add(Measurements(
            endedAt=endedAt,
            startedAt=startedAt,
            elapsed=elapsed,
            args=args,
            kwargs=kwargs,
            context=context,
            method=method,
            name=name,
        ))
        session.commit() 
开发者ID:muatik,项目名称:flask-profiler,代码行数:26,代码来源:sql_alchemy.py

示例7: random_amount

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_UP [as 别名]
def random_amount(rand, *, min_amount=Decimal('0.00'), max_amount=Decimal('10000.00')):
    drange = max_amount - min_amount
    return (min_amount + (drange * Decimal(rand.random()))).quantize(
        Decimal('.01'), rounding=decimal.ROUND_UP
    ) 
开发者ID:GamesDoneQuick,项目名称:donation-tracker,代码行数:7,代码来源:randgen.py

示例8: pydecimal_equivalent_rounding_mode

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_UP [as 别名]
def pydecimal_equivalent_rounding_mode(self):
        return {
            RM.RM_TowardsPositiveInf:      decimal.ROUND_CEILING,
            RM.RM_TowardsNegativeInf:      decimal.ROUND_FLOOR,
            RM.RM_TowardsZero:             decimal.ROUND_DOWN,
            RM.RM_NearestTiesEven:         decimal.ROUND_HALF_EVEN,
            RM.RM_NearestTiesAwayFromZero: decimal.ROUND_UP,
        }[self] 
开发者ID:angr,项目名称:claripy,代码行数:10,代码来源:fp.py

示例9: clean_amount

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_UP [as 别名]
def clean_amount(amount):
    return decimal.Decimal(str(amount)).quantize(decimal.Decimal('.01'), rounding=decimal.ROUND_UP) 
开发者ID:pedroburon,项目名称:tbk,代码行数:4,代码来源:payment.py

示例10: usd

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_UP [as 别名]
def usd(self, amount: Decimal):
        self.pennies = int(amount.quantize(self.PENNY, ROUND_UP) * self.PENNIES) 
开发者ID:lbryio,项目名称:lbry-sdk,代码行数:4,代码来源:attrs.py

示例11: currency_round_up

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_UP [as 别名]
def currency_round_up(money):
    return money.quantize(Decimal('1.00'), rounding=ROUND_UP) 
开发者ID:pyconsk,项目名称:django-konfera,代码行数:4,代码来源:utils.py

示例12: round_up

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_UP [as 别名]
def round_up(n: Decimal, prec: int = 2) -> Decimal:
    return n.quantize(Decimal("." + "0" * prec), rounding=ROUND_UP) 
开发者ID:b2wdigital,项目名称:asgard-api,代码行数:4,代码来源:__init__.py

示例13: adjust_quanity

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_UP [as 别名]
def adjust_quanity(self, q, round_down=True):
        if q == 0:
            return 0

        res = float(Decimal(q).quantize(self.stepSize, rounding=ROUND_DOWN if round_down else ROUND_UP))
        return float(min(max(res, self.minQty), self.maxQty)) 
开发者ID:iilunin,项目名称:crypto-bot,代码行数:8,代码来源:ExchangeInfo.py

示例14: adjust_price

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_UP [as 别名]
def adjust_price(self, q, round_down=True):
        res = round(Decimal(q), 8)

        if self.tickSize:  # if tickSize Enabled
            res = res.quantize(self.tickSize, rounding=ROUND_DOWN if round_down else ROUND_UP)

        if self.minPrice:  # if minPrice Enabled
            res = max(res, self.minPrice)

        if self.maxPrice:  # if minPrice Enabled
            res = min(res, self.maxPrice)

        return float(res) 
开发者ID:iilunin,项目名称:crypto-bot,代码行数:15,代码来源:ExchangeInfo.py

示例15: generate_donation

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_UP [as 别名]
def generate_donation(
    rand,
    *,
    donor=None,
    domain=None,
    event=None,
    min_amount=Decimal('0.01'),
    max_amount=Decimal('1000.00'),
    min_time=None,
    max_time=None,
    donors=None,
    transactionstate=None,
):
    donation = Donation()
    donation.amount = random_amount(rand, min_amount=min_amount, max_amount=max_amount)
    if event:
        donation.event = event
    else:
        donation.event = pick_random_instance(rand, Event)
    if domain:
        donation.domain = domain
    else:
        donation.domain = pick_random_element(rand, DonationDomainChoices)[0]
    donation.domainId = str(rand.getrandbits(64))
    donation.fee = (donation.amount * Decimal(0.03)).quantize(
        Decimal('0.01'), rounding=decimal.ROUND_UP
    )
    donation.comment = random_name(rand, 'Comment')
    donation.commentstate = 'APPROVED'
    donation.readstate = 'READ'
    if not min_time:
        min_time = event.datetime
    if not max_time:
        max_time = min_time + datetime.timedelta(seconds=60 * 60 * 24 * 14)
    donation.timereceived = random_time(rand, min_time, max_time)
    donation.currency = 'USD'
    donation.transactionstate = transactionstate or 'COMPLETED'
    if donation.domain == 'LOCAL':
        assert donation.transactionstate == 'COMPLETED'

    if not donor:
        if donors:
            donor = pick_random_element(rand, donors)
        else:
            donor = pick_random_instance(rand, Donor)
    if not donor:  # no provided donors at all
        donor = generate_donor(rand)
        donor.save()
    donation.donor = donor
    donation.clean()
    return donation 
开发者ID:GamesDoneQuick,项目名称:donation-tracker,代码行数:53,代码来源:randgen.py


注:本文中的decimal.ROUND_UP属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。