本文整理汇总了Python中decimal.ROUND_CEILING属性的典型用法代码示例。如果您正苦于以下问题:Python decimal.ROUND_CEILING属性的具体用法?Python decimal.ROUND_CEILING怎么用?Python decimal.ROUND_CEILING使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类decimal
的用法示例。
在下文中一共展示了decimal.ROUND_CEILING属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calculate_price
# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_CEILING [as 别名]
def calculate_price(self, price, shipping=0.0):
"""
Calculates price and returns it w/ and w/o tax
"""
conf = Configuration.conf()
shipping = shipping or 0.0
if not isinstance(shipping, Decimal):
shipping = Decimal(shipping)
margin = get_margin(price)
vat = Decimal(conf.get("pct_vat", 0.0))
# TWOPLACES = Decimal(10) ** -2 # same as Decimal('0.01')
# @TODO: make rounding configurable!
wo_tax = ((price*100)/(100-margin)+shipping).to_integral_exact(rounding=ROUND_CEILING)
with_tax = (wo_tax*(vat+100)/100).to_integral_exact(rounding=ROUND_CEILING)
return wo_tax, with_tax
示例2: bufferize_country_boundaries
# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_CEILING [as 别名]
def bufferize_country_boundaries(country_code):
if country_code not in COUNTRIES_GEO:
return None
buffer = (
0 if country_code in COUNTRIES_WITH_NO_BUFFER
else
(0.01 if country_code in COUNTRIES_TINIEST else 0.1)
)
precision = decimal.Decimal('0.001') # Three decimal places.
bbox = {
'northeast': [
float(decimal.Decimal(c + buffer if c < +179.9 else c).quantize(precision, decimal.ROUND_CEILING))
for c in COUNTRIES_GEO[country_code]['bbox']['northeast']
],
'southwest': [
float(decimal.Decimal(c - buffer if c > -179.9 else c).quantize(precision, decimal.ROUND_FLOOR))
for c in COUNTRIES_GEO[country_code]['bbox']['southwest']
],
}
return {'bbox': bbox, 'center': COUNTRIES_GEO[country_code]['center']}
示例3: pydecimal_equivalent_rounding_mode
# 需要导入模块: import decimal [as 别名]
# 或者: from decimal import ROUND_CEILING [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]