當前位置: 首頁>>代碼示例>>Python>>正文


Python decimal.ROUND_HALF_DOWN屬性代碼示例

本文整理匯總了Python中decimal.ROUND_HALF_DOWN屬性的典型用法代碼示例。如果您正苦於以下問題:Python decimal.ROUND_HALF_DOWN屬性的具體用法?Python decimal.ROUND_HALF_DOWN怎麽用?Python decimal.ROUND_HALF_DOWN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在decimal的用法示例。


在下文中一共展示了decimal.ROUND_HALF_DOWN屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: round_value

# 需要導入模塊: import decimal [as 別名]
# 或者: from decimal import ROUND_HALF_DOWN [as 別名]
def round_value(value, decimalplaces=0):
    """Rounding function.

    Args:
        value (float): Number to round.
        decimalplaces (int): Number of decimal places of float to represent rounded value.

    Returns:
        rounded (int/float): Rounded value.
    """

    # Rounds to nearest integer (half values are rounded downwards)
    if decimalplaces == 0:
        rounded = int(d.Decimal(value).quantize(d.Decimal('1'), rounding=d.ROUND_HALF_DOWN))

    # Rounds down to nearest float represented by number of decimal places
    else:
        precision = '1.{places}'.format(places='0' * decimalplaces)
        rounded = float(d.Decimal(value).quantize(d.Decimal(precision), rounding=d.ROUND_FLOOR))

    return rounded 
開發者ID:gprMax,項目名稱:gprMax,代碼行數:23,代碼來源:utilities.py

示例2: create_order

# 需要導入模塊: import decimal [as 別名]
# 或者: from decimal import ROUND_HALF_DOWN [as 別名]
def create_order(ordered_items, total, payment_type):
        """create a modified order"""
        order_dct = {
            "items": ordered_items,
            "payment_type":payment_type,
            "total": total}
        
        tax_scale = int((Order.taxrate * 100) + 10000)
        subtotal = int(decimal.Decimal((total * 100) 
                / tax_scale).quantize(
                decimal.Decimal('0.01'),
                    rounding=decimal.ROUND_HALF_DOWN) * 100)

        tax = total - subtotal
        order_dct["subtotal"] = subtotal
        order_dct["tax"] = tax
        return order_dct 
開發者ID:BnetButter,項目名稱:hwk-mirror,代碼行數:19,代碼來源:pos_client.py

示例3: _calc_ratio

# 需要導入模塊: import decimal [as 別名]
# 或者: from decimal import ROUND_HALF_DOWN [as 別名]
def _calc_ratio(part, whole):
    """Calculate ratio

    Returns int
    """
    return int((part / whole * 100).quantize(
        decimal.Decimal('1'), rounding=decimal.ROUND_HALF_DOWN)) 
開發者ID:LuciferJack,項目名稱:python-mysql-pool,代碼行數:9,代碼來源:balancing.py

示例4: _subtotal

# 需要導入模塊: import decimal [as 別名]
# 或者: from decimal import ROUND_HALF_DOWN [as 別名]
def _subtotal(self)->int:
        tax_scale = int((self.taxrate * 100) + 10000)
        result = Decimal((self.total * 100) 
                / tax_scale).quantize(
                    Decimal('0.01'),
                        rounding=ROUND_HALF_DOWN)
        return int(result * 100) 
開發者ID:BnetButter,項目名稱:hwk-mirror,代碼行數:9,代碼來源:metaclass.py

示例5: round_int

# 需要導入模塊: import decimal [as 別名]
# 或者: from decimal import ROUND_HALF_DOWN [as 別名]
def round_int(dec):
    """Round float to nearest int using expected rounding."""

    return int(decimal.Decimal(dec).quantize(decimal.Decimal('0'), decimal.ROUND_HALF_DOWN)) 
開發者ID:facelessuser,項目名稱:ColorHelper,代碼行數:6,代碼來源:rgba.py

示例6: test_round_modify_method

# 需要導入模塊: import decimal [as 別名]
# 或者: from decimal import ROUND_HALF_DOWN [as 別名]
def test_round_modify_method(self):
        assert round_value(3.5, rounding_method=ROUND_HALF_DOWN) == 3.0 
開發者ID:DataDog,項目名稱:integrations-core,代碼行數:4,代碼來源:test_utils.py


注:本文中的decimal.ROUND_HALF_DOWN屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。