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