Python decimal 模块,ROUND_HALF_DOWN 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用decimal.ROUND_HALF_DOWN

项目:flask-zhenai-mongo-echarts    作者:Fretice    | 项目源码 | 文件源码
def __init__(self, min_value=None, max_value=None, force_string=False,
                 precision=2, rounding=decimal.ROUND_HALF_UP, **kwargs):
        """
        :param min_value: Validation rule for the minimum acceptable value.
        :param max_value: Validation rule for the maximum acceptable value.
        :param force_string: Store as a string.
        :param precision: Number of decimal places to store.
        :param rounding: The rounding rule from the python decimal library:

            - decimal.ROUND_CEILING (towards Infinity)
            - decimal.ROUND_DOWN (towards zero)
            - decimal.ROUND_FLOOR (towards -Infinity)
            - decimal.ROUND_HALF_DOWN (to nearest with ties going towards zero)
            - decimal.ROUND_HALF_EVEN (to nearest with ties going to nearest even integer)
            - decimal.ROUND_HALF_UP (to nearest with ties going away from zero)
            - decimal.ROUND_UP (away from zero)
            - decimal.ROUND_05UP (away from zero if last digit after rounding towards zero would have been 0 or 5; otherwise towards zero)

            Defaults to: ``decimal.ROUND_HALF_UP``

        """
        self.min_value = min_value
        self.max_value = max_value
        self.force_string = force_string
        self.precision = precision
        self.rounding = rounding

        super(DecimalField, self).__init__(**kwargs)
项目:python-mysql-pool    作者:LuciferJack    | 项目源码 | 文件源码
def _calc_ratio(part, whole):
    """Calculate ratio

    Returns int
    """
    return int((part / whole * 100).quantize(
        decimal.Decimal('1'), rounding=decimal.ROUND_HALF_DOWN))
项目:importacsv    作者:rasertux    | 项目源码 | 文件源码
def _calc_ratio(part, whole):
    """Calculate ratio

    Returns int
    """
    return int((part/whole*100).quantize(
        decimal.Decimal('1'), rounding=decimal.ROUND_HALF_DOWN))
项目:yangson    作者:CZ-NIC    | 项目源码 | 文件源码
def _eval(self, xctx: XPathContext) -> float:
        dec = decimal.Decimal(self.expr._eval_float(xctx))
        try:
            return float(dec.to_integral_value(
                decimal.ROUND_HALF_UP if dec > 0 else decimal.ROUND_HALF_DOWN))
        except decimal.InvalidOperation:
            return float('nan')
项目:Chorus    作者:DonaldBough    | 项目源码 | 文件源码
def _calc_ratio(part, whole):
    """Calculate ratio

    Returns int
    """
    return int((part/whole*100).quantize(
        decimal.Decimal('1'), rounding=decimal.ROUND_HALF_DOWN))