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


Python defaultfilters.floatformat方法代码示例

本文整理汇总了Python中django.template.defaultfilters.floatformat方法的典型用法代码示例。如果您正苦于以下问题:Python defaultfilters.floatformat方法的具体用法?Python defaultfilters.floatformat怎么用?Python defaultfilters.floatformat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.template.defaultfilters的用法示例。


在下文中一共展示了defaultfilters.floatformat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: display_user_problem

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import floatformat [as 别名]
def display_user_problem(self, participation, contest_problem):
        format_data = (participation.format_data or {}).get(str(contest_problem.id))
        if format_data:
            bonus = format_html('<small> +{bonus}</small>',
                                bonus=floatformat(format_data['bonus'])) if format_data['bonus'] else ''

            return format_html(
                '<td class="{state}"><a href="{url}">{points}{bonus}<div class="solving-time">{time}</div></a></td>',
                state=(('pretest-' if self.contest.run_pretests_only and contest_problem.is_pretested else '') +
                       self.best_solution_state(format_data['points'], contest_problem.points)),
                url=reverse('contest_user_submissions',
                            args=[self.contest.key, participation.user.user.username, contest_problem.problem.code]),
                points=floatformat(format_data['points']),
                bonus=bonus,
                time=nice_repr(timedelta(seconds=format_data['time']), 'noday'),
            )
        else:
            return mark_safe('<td></td>') 
开发者ID:DMOJ,项目名称:online-judge,代码行数:20,代码来源:ecoo.py

示例2: display_user_problem

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import floatformat [as 别名]
def display_user_problem(self, participation, contest_problem):
        format_data = (participation.format_data or {}).get(str(contest_problem.id))
        if format_data:
            penalty = format_html('<small style="color:red"> ({penalty})</small>',
                                  penalty=floatformat(format_data['penalty'])) if format_data['penalty'] else ''
            return format_html(
                '<td class="{state}"><a href="{url}">{points}{penalty}<div class="solving-time">{time}</div></a></td>',
                state=(('pretest-' if self.contest.run_pretests_only and contest_problem.is_pretested else '') +
                       self.best_solution_state(format_data['points'], contest_problem.points)),
                url=reverse('contest_user_submissions',
                            args=[self.contest.key, participation.user.user.username, contest_problem.problem.code]),
                points=floatformat(format_data['points']),
                penalty=penalty,
                time=nice_repr(timedelta(seconds=format_data['time']), 'noday'),
            )
        else:
            return mark_safe('<td></td>') 
开发者ID:DMOJ,项目名称:online-judge,代码行数:19,代码来源:icpc.py

示例3: intword

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import floatformat [as 别名]
def intword(value):
    """
    Converts a large integer to a friendly text representation. Works best
    for numbers over 1 million. For example, 1000000 becomes '1.0 million',
    1200000 becomes '1.2 million' and '1200000000' becomes '1.2 billion'.
    """
    try:
        value = int(value)
    except (TypeError, ValueError):
        return value

    if value < 1000000:
        return value

    def _check_for_i18n(value, float_formatted, string_formatted):
        """
        Use the i18n enabled defaultfilters.floatformat if possible
        """
        if settings.USE_L10N:
            value = defaultfilters.floatformat(value, 1)
            template = string_formatted
        else:
            template = float_formatted
        return template % {'value': value}

    for exponent, converters in intword_converters:
        large_number = 10 ** exponent
        if value < large_number * 1000:
            new_value = value / float(large_number)
            return _check_for_i18n(new_value, *converters(new_value))
    return value 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:33,代码来源:humanize.py

示例4: intword

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import floatformat [as 别名]
def intword(value):
    """
    Convert a large integer to a friendly text representation. Works best
    for numbers over 1 million. For example, 1000000 becomes '1.0 million',
    1200000 becomes '1.2 million' and '1200000000' becomes '1.2 billion'.
    """
    try:
        value = int(value)
    except (TypeError, ValueError):
        return value

    if value < 1000000:
        return value

    def _check_for_i18n(value, float_formatted, string_formatted):
        """
        Use the i18n enabled defaultfilters.floatformat if possible
        """
        if settings.USE_L10N:
            value = defaultfilters.floatformat(value, 1)
            template = string_formatted
        else:
            template = float_formatted
        return template % {'value': value}

    for exponent, converters in intword_converters:
        large_number = 10 ** exponent
        if value < large_number * 1000:
            new_value = value / float(large_number)
            return _check_for_i18n(new_value, *converters(new_value))
    return value 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:33,代码来源:humanize.py

示例5: format_score

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import floatformat [as 别名]
def format_score(value):
    if value is None:
        return "N/A"

    if isinstance(value, bool):
        return '\u2714' if value else '\u2718'

    elif isinstance(value, int):
        return intcomma(value)

    f = floatformat(value, 2)
    if f:
        return f

    return value 
开发者ID:chaoss,项目名称:prospector,代码行数:17,代码来源:metrics.py

示例6: display_participation_result

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import floatformat [as 别名]
def display_participation_result(self, participation):
        return format_html(
            '<td class="user-points">{points}<div class="solving-time">{cumtime}</div></td>',
            points=floatformat(participation.score),
            cumtime=nice_repr(timedelta(seconds=participation.cumtime), 'noday') if self.config['cumtime'] else '',
        ) 
开发者ID:DMOJ,项目名称:online-judge,代码行数:8,代码来源:ecoo.py

示例7: display_user_problem

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import floatformat [as 别名]
def display_user_problem(self, participation, contest_problem):
        format_data = (participation.format_data or {}).get(str(contest_problem.id))
        if format_data:
            return format_html(
                '<td class="{state}"><a href="{url}">{points}<div class="solving-time">{time}</div></a></td>',
                state=(('pretest-' if self.contest.run_pretests_only and contest_problem.is_pretested else '') +
                       self.best_solution_state(format_data['points'], contest_problem.points)),
                url=reverse('contest_user_submissions',
                            args=[self.contest.key, participation.user.user.username, contest_problem.problem.code]),
                points=floatformat(format_data['points']),
                time=nice_repr(timedelta(seconds=format_data['time']), 'noday') if self.config['cumtime'] else '',
            )
        else:
            return mark_safe('<td></td>') 
开发者ID:DMOJ,项目名称:online-judge,代码行数:16,代码来源:legacy_ioi.py

示例8: display_user_problem

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import floatformat [as 别名]
def display_user_problem(self, participation, contest_problem):
        format_data = (participation.format_data or {}).get(str(contest_problem.id))
        if format_data:
            return format_html(
                u'<td class="{state}"><a href="{url}">{points}<div class="solving-time">{time}</div></a></td>',
                state=(('pretest-' if self.contest.run_pretests_only and contest_problem.is_pretested else '') +
                       self.best_solution_state(format_data['points'], contest_problem.points)),
                url=reverse('contest_user_submissions',
                            args=[self.contest.key, participation.user.user.username, contest_problem.problem.code]),
                points=floatformat(format_data['points']),
                time=nice_repr(timedelta(seconds=format_data['time']), 'noday'),
            )
        else:
            return mark_safe('<td></td>') 
开发者ID:DMOJ,项目名称:online-judge,代码行数:16,代码来源:default.py

示例9: display_participation_result

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import floatformat [as 别名]
def display_participation_result(self, participation):
        return format_html(
            u'<td class="user-points">{points}<div class="solving-time">{cumtime}</div></td>',
            points=floatformat(participation.score),
            cumtime=nice_repr(timedelta(seconds=participation.cumtime), 'noday'),
        ) 
开发者ID:DMOJ,项目名称:online-judge,代码行数:8,代码来源:default.py

示例10: intword

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import floatformat [as 别名]
def intword(value):
    """
    Convert a large integer to a friendly text representation. Works best
    for numbers over 1 million. For example, 1000000 becomes '1.0 million',
    1200000 becomes '1.2 million' and '1200000000' becomes '1.2 billion'.
    """
    try:
        value = int(value)
    except (TypeError, ValueError):
        return value

    if value < 1000000:
        return value

    def _check_for_i18n(value, float_formatted, string_formatted):
        """
        Use the i18n enabled defaultfilters.floatformat if possible
        """
        if settings.USE_L10N:
            value = defaultfilters.floatformat(value, 1)
            template = string_formatted
        else:
            template = float_formatted
        return template % {'value': value}

    for exponent, converters in intword_converters:
        large_number = 10 ** exponent
        if value < large_number * 1000:
            new_value = value / large_number
            return _check_for_i18n(new_value, *converters(new_value))
    return value 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:33,代码来源:humanize.py

示例11: percent

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import floatformat [as 别名]
def percent(value, decimal_places=0):
    if value is None:
        return None
    try:
        value = float(value)
    except ValueError:
        return None
    return floatformat(value * 100.0, decimal_places) + '%' 
开发者ID:tiagoarasilva,项目名称:cookiecutter-django,代码行数:10,代码来源:numberhelpers.py

示例12: test_inputs

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import floatformat [as 别名]
def test_inputs(self):
        self.assertEqual(floatformat(7.7), '7.7')
        self.assertEqual(floatformat(7.0), '7')
        self.assertEqual(floatformat(0.7), '0.7')
        self.assertEqual(floatformat(0.07), '0.1')
        self.assertEqual(floatformat(0.007), '0.0')
        self.assertEqual(floatformat(0.0), '0')
        self.assertEqual(floatformat(7.7, 0), '8')
        self.assertEqual(floatformat(7.7, 3), '7.700')
        self.assertEqual(floatformat(6.000000, 3), '6.000')
        self.assertEqual(floatformat(6.200000, 3), '6.200')
        self.assertEqual(floatformat(6.200000, -3), '6.200')
        self.assertEqual(floatformat(13.1031, -3), '13.103')
        self.assertEqual(floatformat(11.1197, -2), '11.12')
        self.assertEqual(floatformat(11.0000, -2), '11')
        self.assertEqual(floatformat(11.000001, -2), '11.00')
        self.assertEqual(floatformat(8.2798, 3), '8.280')
        self.assertEqual(floatformat(5555.555, 2), '5555.56')
        self.assertEqual(floatformat(001.3000, 2), '1.30')
        self.assertEqual(floatformat(0.12345, 2), '0.12')
        self.assertEqual(floatformat(Decimal('555.555'), 2), '555.56')
        self.assertEqual(floatformat(Decimal('09.000')), '9')
        self.assertEqual(floatformat('foo'), '')
        self.assertEqual(floatformat(13.1031, 'bar'), '13.1031')
        self.assertEqual(floatformat(18.125, 2), '18.13')
        self.assertEqual(floatformat('foo', 'bar'), '')
        self.assertEqual(floatformat('¿Cómo esta usted?'), '')
        self.assertEqual(floatformat(None), '')
        self.assertEqual(floatformat(-1.323297138040798e+35, 2), '-132329713804079800000000000000000000.00')
        self.assertEqual(floatformat(-1.323297138040798e+35, -2), '-132329713804079800000000000000000000')
        self.assertEqual(floatformat(1.5e-15, 20), '0.00000000000000150000')
        self.assertEqual(floatformat(1.5e-15, -20), '0.00000000000000150000')
        self.assertEqual(floatformat(1.00000000000000015, 16), '1.0000000000000002') 
开发者ID:nesdis,项目名称:djongo,代码行数:35,代码来源:test_floatformat.py

示例13: test_zero_values

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import floatformat [as 别名]
def test_zero_values(self):
        self.assertEqual(floatformat(0, 6), '0.000000')
        self.assertEqual(floatformat(0, 7), '0.0000000')
        self.assertEqual(floatformat(0, 10), '0.0000000000')
        self.assertEqual(floatformat(0.000000000000000000015, 20), '0.00000000000000000002') 
开发者ID:nesdis,项目名称:djongo,代码行数:7,代码来源:test_floatformat.py

示例14: test_infinity

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import floatformat [as 别名]
def test_infinity(self):
        pos_inf = float(1e30000)
        neg_inf = float(-1e30000)
        self.assertEqual(floatformat(pos_inf), 'inf')
        self.assertEqual(floatformat(neg_inf), '-inf')
        self.assertEqual(floatformat(pos_inf / pos_inf), 'nan') 
开发者ID:nesdis,项目名称:djongo,代码行数:8,代码来源:test_floatformat.py

示例15: test_float_dunder_method

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import floatformat [as 别名]
def test_float_dunder_method(self):
        class FloatWrapper:
            def __init__(self, value):
                self.value = value

            def __float__(self):
                return self.value

        self.assertEqual(floatformat(FloatWrapper(11.000001), -2), '11.00') 
开发者ID:nesdis,项目名称:djongo,代码行数:11,代码来源:test_floatformat.py


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