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


Python decimal.ROUND_CEILING属性代码示例

本文整理汇总了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 
开发者ID:fpsw,项目名称:Servo,代码行数:21,代码来源:product.py

示例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']} 
开发者ID:tejoesperanto,项目名称:pasportaservo,代码行数:22,代码来源:utils.py

示例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] 
开发者ID:angr,项目名称:claripy,代码行数:10,代码来源:fp.py


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