當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。