本文整理汇总了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)
示例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()
)
示例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
示例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)
示例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'])
示例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
示例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)
示例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
示例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()
)
示例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)
示例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),
)
示例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)
示例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)
示例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)
示例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