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


Python decimal.ROUND_DOWN属性代码示例

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


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

示例1: contain

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_DOWN [as 别名]
def contain(self, exchange_pair: 'ExchangePair'):
        options = exchange_pair.exchange.options
        price = exchange_pair.price

        if exchange_pair.pair.base == self.instrument:
            size = self.size
            return Quantity(self.instrument, min(size, options.max_trade_size), self.path_id)

        size = self.size * price
        if size < options.max_trade_size:
            return Quantity(self.instrument, self.size, self.path_id)

        max_trade_size = Decimal(options.max_trade_size)
        contained_size = max_trade_size / price
        contained_size = contained_size.quantize(Decimal(10)**-self.instrument.precision, rounding=ROUND_DOWN)
        return Quantity(self.instrument, contained_size, self.path_id) 
开发者ID:tensortrade-org,项目名称:tensortrade,代码行数:18,代码来源:quantity.py

示例2: satoshi_to_currency_cached

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_DOWN [as 别名]
def satoshi_to_currency_cached(num, currency):
    """Converts a given number of satoshi to another currency as a formatted
    string rounded down to the proper number of decimal places. Results are
    cached using a decorator for 60 seconds by default. See :ref:`cache times`.

    :param num: The number of satoshi.
    :type num: ``int``
    :param currency: One of the :ref:`supported currencies`.
    :type currency: ``str``
    :rtype: ``str``
    """
    return '{:f}'.format(
        Decimal(num / Decimal(currency_to_satoshi_cached(1, currency)))
        .quantize(Decimal('0.' + '0' * CURRENCY_PRECISION[currency]), rounding=ROUND_DOWN)
        .normalize()
    ) 
开发者ID:ofek,项目名称:bit,代码行数:18,代码来源:rates.py

示例3: _fallout_report_data

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_DOWN [as 别名]
def _fallout_report_data(request, start_date, end_date):
    sub_unit_ids = Unit.sub_unit_ids(request.units)
    fac_roles = Role.objects.filter(role='FAC', unit__id__in=sub_unit_ids).select_related('person', 'unit')
    table = []
    tot_fallout = 0
    for role in fac_roles:
        unit = role.unit
        p = role.person
        salary = FacultySummary(p).salary(end_date, units=[unit])
        salary_events = CareerEvent.objects.approved().overlaps_daterange(start_date, end_date) \
            .filter(person=p, unit=unit, flags=CareerEvent.flags.affects_salary)
        for event in salary_events:
            if event.event_type == 'LEAVE' or event.event_type == 'STUDYLEAVE':
                days = event.get_duration_within_range(start_date, end_date)
                fraction = FacultySummary(p).salary_event_info(event)[1]
                d = fraction.denominator
                n = fraction.numerator
                fallout = Decimal((salary - salary*n/d)*days/365).quantize(Decimal('.01'), rounding=ROUND_DOWN)
                tot_fallout += fallout

                table += [(unit.label, p, event, event.start_date, event.end_date, days, salary, fraction, fallout)]
    return table 
开发者ID:sfu-fas,项目名称:coursys,代码行数:24,代码来源:views.py

示例4: calculate_price

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_DOWN [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

示例5: test_initialize_with_all_args

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_DOWN [as 别名]
def test_initialize_with_all_args(self):
        """
        Create Payment with all it's args
        """
        amount = Decimal(self.payment_kwargs['amount']).quantize(Decimal('.01'), rounding=ROUND_DOWN)
        payment = Payment(**self.payment_kwargs)
        self.assertEqual(payment.commerce, self.payment_kwargs['commerce'])
        self.assertEqual(payment.request_ip, self.payment_kwargs['request_ip'])
        self.assertEqual(payment.amount, amount)
        self.assertEqual(payment.order_id, self.payment_kwargs['order_id'])
        self.assertEqual(
            payment.success_url, self.payment_kwargs['success_url'])
        self.assertEqual(payment.confirmation_url, self.payment_kwargs['confirmation_url'])
        self.assertEqual(payment.session_id, self.payment_kwargs['session_id'])
        self.assertEqual(
            payment.failure_url, self.payment_kwargs['failure_url']) 
开发者ID:pedroburon,项目名称:tbk,代码行数:18,代码来源:test_payment.py

示例6: _op

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_DOWN [as 别名]
def _op(self, left, right):
        # evaluate the operation using true division or floor division
        assert type(left) is type(right)
        if not right:
            raise ZeroDivisionException("Division by zero")

        if isinstance(left, decimal.Decimal):
            value = left / right
            if value < 0:
                # the EVM always truncates toward zero
                value = -(-left / right)
            # ensure that the result is truncated to MAX_DECIMAL_PLACES
            return value.quantize(
                decimal.Decimal(f"{1:0.{MAX_DECIMAL_PLACES}f}"), decimal.ROUND_DOWN
            )
        else:
            value = left // right
            if value < 0:
                return -(-left // right)
            return value 
开发者ID:vyperlang,项目名称:vyper,代码行数:22,代码来源:nodes.py

示例7: remaining_emission

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_DOWN [as 别名]
def remaining_emission(block_n, dev_config: DevConfig) -> Decimal:
    # TODO: This is more related to the way QRL works.. Move to another place
    """
    calculate remaining emission at block_n: N=total initial coin supply, coeff = decay constant
    need to use decimal as floating point not precise enough on different platforms..
    :param block_n:
    :return:

    >>> from qrl.core import config
    >>> remaining_emission(0, config.dev)
    Decimal('40000000000000000')
    >>> remaining_emission(1, config.dev)
    Decimal('39999993343650538')
    >>> remaining_emission(2, config.dev)
    Decimal('39999986687302185')
    >>> remaining_emission(100, config.dev)
    Decimal('39999334370536850')
    """
    coeff = calc_coeff(dev_config)
    return (dev_config.coin_remaining_at_genesis * dev_config.shor_per_quanta * Decimal(-coeff * block_n).exp()) \
        .quantize(Decimal('1.'), rounding=decimal.ROUND_DOWN) 
开发者ID:theQRL,项目名称:QRL,代码行数:23,代码来源:formulas.py

示例8: make_change

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_DOWN [as 别名]
def make_change(from_node, amount_in, amount_out, fee):
    """
    Create change output(s), return them
    """
    outputs = {}
    amount = amount_out + fee
    change = amount_in - amount
    if change > amount * 2:
        # Create an extra change output to break up big inputs
        change_address = from_node.getnewaddress()
        # Split change in two, being careful of rounding:
        outputs[change_address] = Decimal(change / 2).quantize(Decimal('0.00000001'), rounding=ROUND_DOWN)
        change = amount_in - amount - outputs[change_address]
    if change > 0:
        outputs[from_node.getnewaddress()] = change
    return outputs 
开发者ID:initc3,项目名称:i-cant-believe-its-not-stake,代码行数:18,代码来源:util.py

示例9: satoshi_to_currency

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_DOWN [as 别名]
def satoshi_to_currency(num, currency):
    """Converts a given number of satoshi to another currency as a formatted
    string rounded down to the proper number of decimal places.

    :param num: The number of satoshi.
    :type num: ``int``
    :param currency: One of the :ref:`supported currencies`.
    :type currency: ``str``
    :rtype: ``str``
    """
    return '{:f}'.format(
        Decimal(num / Decimal(EXCHANGE_RATES[currency]()))
        .quantize(Decimal('0.' + '0' * CURRENCY_PRECISION[currency]), rounding=ROUND_DOWN)
        .normalize()
    ) 
开发者ID:ofek,项目名称:bit,代码行数:17,代码来源:rates.py

示例10: salary

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_DOWN [as 别名]
def salary(self, date, units=None):
        """Returns the person's total pay as of a given date."""
        tot_salary = 0
        tot_fraction = 1
        tot_bonus = 0

        for event in self.salary_events(date, units=units):
            add_salary, salary_fraction, add_bonus = self.salary_event_info(event)

            tot_salary += add_salary
            tot_fraction *= salary_fraction
            tot_bonus += add_bonus

        pay = tot_salary * tot_fraction.numerator/tot_fraction.denominator + tot_bonus
        return Decimal(pay).quantize(Decimal('.01'), rounding=ROUND_DOWN) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:17,代码来源:processing.py

示例11: salary_event_info

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_DOWN [as 别名]
def salary_event_info(self, event):
        """Returns the rounded annual salary adjust data for an event."""
        handler = event.get_handler()
        add_salary, salary_fraction, add_bonus = handler.salary_adjust_annually()

        return (
            Decimal(add_salary).quantize(Decimal('.01'), rounding=ROUND_DOWN),
            salary_fraction,
            Decimal(add_bonus).quantize(Decimal('.01'), rounding=ROUND_DOWN),
        ) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:12,代码来源:processing.py

示例12: round_fiat

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_DOWN [as 别名]
def round_fiat(self, money):
        return Decimal(money).quantize(Decimal('.01'), rounding=ROUND_DOWN) 
开发者ID:mcardillo55,项目名称:cbpro-trader,代码行数:4,代码来源:TradeEngine.py

示例13: round_coin

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_DOWN [as 别名]
def round_coin(self, money):
        return Decimal(money).quantize(Decimal('.00000001'), rounding=ROUND_DOWN) 
开发者ID:mcardillo55,项目名称:cbpro-trader,代码行数:4,代码来源:TradeEngine.py

示例14: f2qdec

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_DOWN [as 别名]
def f2qdec(self, f):
        return dec.Decimal(repr(f)).quantize(self.car_prec, dec.ROUND_DOWN) 
开发者ID:pyiron,项目名称:pyiron,代码行数:4,代码来源:structure.py

示例15: convert_value

# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_DOWN [as 别名]
def convert_value(cls, value, to, prec=33):
        """
        Convert values from/to pip/bip.
        Args:
            value (string|int|Decimal|float): value to convert
            to (string): coin to convert value to
            prec (int): decimal context precision (decimal number length)
        Returns:
            int|Decimal
        """
        # Get default decimal context
        context = decimal.getcontext()
        # Set temporary decimal context for calculation
        decimal.setcontext(
            decimal.Context(prec=prec, rounding=decimal.ROUND_DOWN)
        )

        # PIP in BIP in Decimal
        default = decimal.Decimal(str(cls.DEFAULT))
        # Value in Decimal
        value = decimal.Decimal(str(value))

        # Make conversion
        if to == 'pip':
            value = int(value * default)
        elif to == 'bip':
            value /= default

        # Reset decimal context to default
        decimal.setcontext(context)

        return value 
开发者ID:U-node,项目名称:minter-sdk,代码行数:34,代码来源:__init__.py


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