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


Python decimal.ROUND_FLOOR屬性代碼示例

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


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

示例1: bufferize_country_boundaries

# 需要導入模塊: import decimal [as 別名]
# 或者: from decimal import ROUND_FLOOR [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

示例2: round_value

# 需要導入模塊: import decimal [as 別名]
# 或者: from decimal import ROUND_FLOOR [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

示例3: _converter_date

# 需要導入模塊: import decimal [as 別名]
# 或者: from decimal import ROUND_FLOOR [as 別名]
def _converter_date(value):
        m = iso8601.match(value)
        year = int(m.group("year"))
        month = int(m.group("month") or "1")
        day = int(m.group("day") or "1")
        hour = int(m.group("hour") or "0")
        minute = int(m.group("minute") or "0")
        second = decimal.Decimal(m.group("second") or "0")
        seconds = second.to_integral(decimal.ROUND_FLOOR)
        milliseconds = (second - seconds) * 1000000
        tzd = m.group("tzd") or "Z"
        dt = datetime.datetime(year, month, day, hour, minute, seconds, milliseconds)
        if tzd != "Z":
            tzd_hours, tzd_minutes = [int(x) for x in tzd.split(":")]
            tzd_hours *= -1
            if tzd_hours < 0:
                tzd_minutes *= -1
            dt = dt + datetime.timedelta(hours=tzd_hours, minutes=tzd_minutes)
        return dt 
開發者ID:linuxerwang,項目名稱:pdf-quench,代碼行數:21,代碼來源:xmp.py

示例4: best_rational_approximation

# 需要導入模塊: import decimal [as 別名]
# 或者: from decimal import ROUND_FLOOR [as 別名]
def best_rational_approximation(x):
    x = Decimal(x)
    int32_max = Decimal(2147483647)
    fractions = [[Decimal(0), Decimal(1)], [Decimal(1), Decimal(0)]]
    i = 2
    while True:
        if x > int32_max:
            break
        a = x.to_integral_exact(rounding=ROUND_FLOOR)
        f = x - a
        h = a * fractions[i - 1][0] + fractions[i - 2][0]
        k = a * fractions[i - 1][1] + fractions[i - 2][1]
        if h > int32_max or k > int32_max:
            break
        fractions.append([h, k])
        if f.is_zero():
            break
        x = 1 / f
        i = i + 1
    n = fractions[len(fractions) - 1][0]
    d = fractions[len(fractions) - 1][1]
    if n.is_zero() or d.is_zero():
        raise NoApproximationError("Couldn't find approximation.")
    return {"n": int(n), "d": int(d)} 
開發者ID:StellarCN,項目名稱:py-stellar-base,代碼行數:26,代碼來源:utils.py

示例5: round_decimal

# 需要導入模塊: import decimal [as 別名]
# 或者: from decimal import ROUND_FLOOR [as 別名]
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
            ).to_integral(decimal.ROUND_FLOOR) / \
        pow(10, prec) 
開發者ID:jpush,項目名稱:jbox,代碼行數:10,代碼來源:util.py

示例6: stepBy

# 需要導入模塊: import decimal [as 別名]
# 或者: from decimal import ROUND_FLOOR [as 別名]
def stepBy(self, n):
        n = D(int(n))   ## n must be integral number of steps.
        s = [D(-1), D(1)][n >= 0]  ## determine sign of step
        val = self.val
        
        for i in range(int(abs(n))):
            
            if self.opts['log']:
                raise Exception("Log mode no longer supported.")
            #    step = abs(val) * self.opts['step']
            #    if 'minStep' in self.opts:
            #        step = max(step, self.opts['minStep'])
            #    val += step * s
            if self.opts['dec']:
                if val == 0:
                    step = self.opts['minStep']
                    exp = None
                else:
                    vs = [D(-1), D(1)][val >= 0]
                    #exp = D(int(abs(val*(D('1.01')**(s*vs))).log10()))
                    fudge = D('1.01')**(s*vs) ## fudge factor. at some places, the step size depends on the step sign.
                    exp = abs(val * fudge).log10().quantize(1, decimal.ROUND_FLOOR)
                    step = self.opts['step'] * D(10)**exp
                if 'minStep' in self.opts:
                    step = max(step, self.opts['minStep'])
                val += s * step
                #print "Exp:", exp, "step", step, "val", val
            else:
                val += s*self.opts['step']
                
            if 'minStep' in self.opts and abs(val) < self.opts['minStep']:
                val = D(0)
        self.setValue(val, delaySignal=True)  ## note all steps (arrow buttons, wheel, up/down keys..) emit delayed signals only. 
開發者ID:SrikanthVelpuri,項目名稱:tf-pose,代碼行數:35,代碼來源:SpinBox.py

示例7: to_percent

# 需要導入模塊: import decimal [as 別名]
# 或者: from decimal import ROUND_FLOOR [as 別名]
def to_percent(v: Decimal, q=CHANCE_MIN) -> str:
    s = str((v * 100).quantize(q, rounding=ROUND_FLOOR))
    if '.' in s:
        return s.rstrip('0').rstrip('.')
    return s 
開發者ID:item4,項目名稱:yui,代碼行數:7,代碼來源:gacha.py

示例8: calculate_mpg

# 需要導入模塊: import decimal [as 別名]
# 或者: from decimal import ROUND_FLOOR [as 別名]
def calculate_mpg(self):
        """
        Calculate ``calculated_mpg`` field.

        :returns: True if recalculate, False if unable to calculate
        :rtype: bool
        """
        if self.gallons is None:
            logger.warning(
                'Gallons is none; cannot recalculate MPG for %s', self
            )
            return False
        if self.odometer_miles is None:
            logger.warning(
                'odometer_miles is none; cannot recalculate MPG for %s', self
            )
            return False
        prev = self._previous_entry()
        if prev is None:
            logger.warning('Previous entry is None; cannot recalculate MPG '
                           'for %s', self)
            return False
        distance = self.odometer_miles - prev.odometer_miles
        self.calculated_miles = distance
        self.calculated_mpg = (
            (distance * Decimal(1.0)) / self.gallons
        ).quantize(Decimal('.001'), rounding=ROUND_FLOOR)
        logger.debug('Calculate MPG for fill %d: distance=%s mpg=%s',
                     self.id, distance, self.calculated_mpg)
        inspect(self).session.add(self) 
開發者ID:jantman,項目名稱:biweeklybudget,代碼行數:32,代碼來源:fuel.py

示例9: pydecimal_equivalent_rounding_mode

# 需要導入模塊: import decimal [as 別名]
# 或者: from decimal import ROUND_FLOOR [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

示例10: decimal_truncate

# 需要導入模塊: import decimal [as 別名]
# 或者: from decimal import ROUND_FLOOR [as 別名]
def decimal_truncate(val, decimal_places=DECIMAL_PLACES, rounding=ROUND_FLOOR):
    q = "0"
    if decimal_places != 0:
        q += "." + "0" * decimal_places

    return val.quantize(Decimal(q), rounding=rounding) 
開發者ID:vyperlang,項目名稱:vyper,代碼行數:8,代碼來源:test_sqrt.py

示例11: round_decimal

# 需要導入模塊: import decimal [as 別名]
# 或者: from decimal import ROUND_FLOOR [as 別名]
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)).to_integral(
        decimal.ROUND_FLOOR
    ) / pow(10, prec) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:10,代碼來源:util.py

示例12: bitflyer_fee_func

# 需要導入模塊: import decimal [as 別名]
# 或者: from decimal import ROUND_FLOOR [as 別名]
def bitflyer_fee_func(symbol, side, price, amount, fee_rate):
    ffb = 0  # fee from balance
    if symbol == 'BTC/JPY':
        f = Decimal(str(amount)) * Decimal(str(fee_rate))
        ffb = float(f.quantize(Decimal('0.00000001'), ROUND_FLOOR))
    info = {'commission': ffb, 'sfd': 0}
    return price * amount * fee_rate, ffb, info 
開發者ID:penta2019,項目名稱:btc_bot_framework,代碼行數:9,代碼來源:order_simulator.py

示例13: round_decimal

# 需要導入模塊: import decimal [as 別名]
# 或者: from decimal import ROUND_FLOOR [as 別名]
def round_decimal(value, prec):
    if isinstance(value, float):
        return round(value, prec)

    # can also use shift() here but that is 2.6 only
    return (value * decimal.Decimal("1" + "0" * prec)
                    ).to_integral(decimal.ROUND_FLOOR) / \
                        pow(10, prec) 
開發者ID:binhex,項目名稱:moviegrabber,代碼行數:10,代碼來源:util.py


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