• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python numbers.format_scientific函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中babel.numbers.format_scientific函数的典型用法代码示例。如果您正苦于以下问题:Python format_scientific函数的具体用法?Python format_scientific怎么用?Python format_scientific使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_default_scientific_format

def test_default_scientific_format():
    """ Check the scientific format method auto-correct the rendering pattern
    in case of a missing fractional part.
    """
    assert numbers.format_scientific(12345, locale='en_US') == u'1.2345E4'
    assert numbers.format_scientific(12345.678, locale='en_US') == u'1.2345678E4'
    assert numbers.format_scientific(12345, u'#E0', locale='en_US') == u'1.2345E4'
    assert numbers.format_scientific(12345.678, u'#E0', locale='en_US') == u'1.2345678E4'
开发者ID:JonathanRRogers,项目名称:babel,代码行数:8,代码来源:test_numbers.py


示例2: test_format_scientific

def test_format_scientific():
    assert numbers.format_scientific(10000, locale='en_US') == u'1E4'
    assert numbers.format_scientific(4234567, u'#.#E0', locale='en_US') == u'4.2E6'
    assert numbers.format_scientific(4234567, u'0E0000', locale='en_US') == u'4.234567E0006'
    assert numbers.format_scientific(4234567, u'##0E00', locale='en_US') == u'4.234567E06'
    assert numbers.format_scientific(4234567, u'##00E00', locale='en_US') == u'42.34567E05'
    assert numbers.format_scientific(4234567, u'0,000E00', locale='en_US') == u'4,234.567E03'
    assert numbers.format_scientific(4234567, u'##0.#####E00', locale='en_US') == u'4.23457E06'
    assert numbers.format_scientific(4234567, u'##0.##E00', locale='en_US') == u'4.23E06'
    assert numbers.format_scientific(42, u'00000.000000E0000', locale='en_US') == u'42000.000000E-0003'
开发者ID:JonathanRRogers,项目名称:babel,代码行数:10,代码来源:test_numbers.py


示例3: format_scientific

def format_scientific(number, format=None, locale=None):
    """Returns value formatted in scientific notation for a specific locale.

    .. code-block:: python

       >>> format_scientific(10000, locale='en_US')
       u'1E4'

    The format pattern can also be specified explicitly:

    .. code-block:: python

       >>> format_scientific(1234567, u'##0E00', locale='en_US')
       u'1.23E06'

    :param number:
        The number to format.
    :param format:
        Notation format.
    :param locale:
        A locale code. If not set, uses the currently loaded locale.
    :returns:
        Value formatted in scientific notation.
    """
    locale = locale or get_locale()
    return numbers.format_scientific(number, format=format, locale=locale)
开发者ID:Hubble1,项目名称:eventgrinder,代码行数:26,代码来源:i18n.py


示例4: format_scientific

def format_scientific(number, format=None):
    """Return value formatted in scientific notation for the locale in request

    :param number: the number to format
    :param format: the format to use
    :return: the formatted percent number
    :rtype: unicode
    """
    locale = get_locale()
    return numbers.format_scientific(number, format=format, locale=locale)
开发者ID:dpgaspar,项目名称:flask-babelPkg,代码行数:10,代码来源:__init__.py


示例5: format_scientific

    def format_scientific(self, number, format=None):
        """Return value formatted in scientific notation

        >>> Locale('en', 'US').format_scientific(10000)
        u'1E4'

        The format pattern can also be specified explicitly:

        >>> Locale('en', 'US').format_scientific(1234567, u'##0E00')
        u'1.23E06'
        """
        return numbers.format_scientific(number, format, self)
开发者ID:nagareproject,项目名称:core,代码行数:12,代码来源:i18n.py


示例6: format_scientific

    def format_scientific(self, number, format=None, locale=None, **kwargs):
        """Return value formatted in scientific notation for the locale in
        the current request.

        :param number: the number to format
        :param format: the format to use as
            `documented by Babel <http://babel.pocoo.org/docs/numbers/#pattern-syntax>`_.
        :param locale: Overwrite the global locale.

        """
        if number in ('', None):
            return ''
        locale = utils.normalize_locale(locale) or self.get_locale()
        return numbers.format_scientific(number, format=format, locale=locale, **kwargs)
开发者ID:jpscaletti,项目名称:allspeak,代码行数:14,代码来源:l10n.py


示例7: format_scientific

def format_scientific(number, format=None):
    """Return a decimal number formatted in scientific notation.

    If you specify just the number, it uses the default format pattern
    for the current locale. The format parameter can be used to force a
    custom pattern. See the `Babel documentation`_ for details on the
    pattern syntax.

    This function is also available in the template context as filter
    named `scientificformat`.

    .. _`Babel documentation`: http://babel.edgewall.org/wiki/Documentation/numbers.html#pattern-syntax
    """
    locale = get_locale()
    return numbers.format_scientific(number, format=format, locale=locale)
开发者ID:lalinsky,项目名称:flask-babel,代码行数:15,代码来源:babel.py


示例8: format_scientific

def format_scientific(number, format=None):
    """Return value formatted in scientific notation for a specific locale.

    >>> format_scientific(10000, locale='en_US')
    u'1E4'

    The format pattern can also be specified explicitly:

    >>> format_scientific(1234567, u'##0E00', locale='en_US')
    u'1.23E06'

    :param number:
        The number to format.
    :param format:
    :return:
        Value formatted in scientific notation.
    """
    return numbers.format_scientific(number, format=format, locale=local.locale)
开发者ID:aristidb,项目名称:cppbash,代码行数:18,代码来源:__init__.py


示例9: format_scientific

    def format_scientific(self, number, format=None):
        """Returns value formatted in scientific notation for the current
        locale. Example::

            >>> format_scientific(10000, locale='en_US')
            u'1E4'

        The format pattern can also be specified explicitly::

            >>> format_scientific(1234567, u'##0E00', locale='en_US')
            u'1.23E06'

        :param number:
            The number to format.
        :param format:
            Notation format.
        :returns:
            Value formatted in scientific notation.
        """
        return numbers.format_scientific(number, format=format,
                                         locale=self.locale)
开发者ID:404minds,项目名称:quiz-forest,代码行数:21,代码来源:i18n.py


示例10: scientific

 def scientific(self, number):
     """Return a number formatted using scientific notation for the locale.
     
     :see: `babel.numbers.format_scientific`
     """
     return format_scientific(number, locale=self.locale)
开发者ID:10-01,项目名称:alc-server,代码行数:6,代码来源:support.py


示例11: test_scientific_notation

 def test_scientific_notation(self):
     fmt = numbers.format_scientific(0.1, '#E0', locale='en_US')
     self.assertEqual(fmt, '1E-1')
     fmt = numbers.format_scientific(0.01, '#E0', locale='en_US')
     self.assertEqual(fmt, '1E-2')
     fmt = numbers.format_scientific(10, '#E0', locale='en_US')
     self.assertEqual(fmt, '1E1')
     fmt = numbers.format_scientific(1234, '0.###E0', locale='en_US')
     self.assertEqual(fmt, '1.234E3')
     fmt = numbers.format_scientific(1234, '0.#E0', locale='en_US')
     self.assertEqual(fmt, '1.2E3')
     # Exponent grouping
     fmt = numbers.format_scientific(12345, '##0.####E0', locale='en_US')
     self.assertEqual(fmt, '12.345E3')
     # Minimum number of int digits
     fmt = numbers.format_scientific(12345, '00.###E0', locale='en_US')
     self.assertEqual(fmt, '12.345E3')
     fmt = numbers.format_scientific(-12345.6, '00.###E0', locale='en_US')
     self.assertEqual(fmt, '-12.346E3')
     fmt = numbers.format_scientific(-0.01234, '00.###E0', locale='en_US')
     self.assertEqual(fmt, '-12.34E-3')
     # Custom pattern suffic
     fmt = numbers.format_scientific(123.45, '#.##E0 m/s', locale='en_US')
     self.assertEqual(fmt, '1.23E2 m/s')
     # Exponent patterns
     fmt = numbers.format_scientific(123.45, '#.##E00 m/s', locale='en_US')
     self.assertEqual(fmt, '1.23E02 m/s')
     fmt = numbers.format_scientific(0.012345, '#.##E00 m/s', locale='en_US')
     self.assertEqual(fmt, '1.23E-02 m/s')
     fmt = numbers.format_scientific(Decimal('12345'), '#.##E+00 m/s',
     locale='en_US')
     self.assertEqual(fmt, '1.23E+04 m/s')
     # 0 (see ticket #99)
     fmt = numbers.format_scientific(0, '#E0', locale='en_US')
     self.assertEqual(fmt, '0E0')
开发者ID:vsajip,项目名称:babel3,代码行数:35,代码来源:numbers.py


示例12: test_format_scientific

def test_format_scientific():
    assert numbers.format_scientific(10000, locale='en_US') == u'1E4'
    assert (numbers.format_scientific(1234567, u'##0E00', locale='en_US')
            == u'1.23E06')
开发者ID:gmist,项目名称:babel,代码行数:4,代码来源:test_numbers.py


示例13: test_scientific_exponent_displayed_as_integer

def test_scientific_exponent_displayed_as_integer():
    assert numbers.format_scientific(100000, locale='en_US') == u'1E5'
开发者ID:gmist,项目名称:babel,代码行数:2,代码来源:test_numbers.py


示例14: test_format_scientific_quantization

def test_format_scientific_quantization():
    # Test all locales.
    for locale_code in localedata.locale_identifiers():
        assert numbers.format_scientific(
            '0.9999999999', locale=locale_code, decimal_quantization=False).find('999999999') > -1
开发者ID:JonathanRRogers,项目名称:babel,代码行数:5,代码来源:test_numbers.py


示例15: test_format_scientific_precision

def test_format_scientific_precision(input_value, expected_value):
    # Test precision conservation.
    assert numbers.format_scientific(
        decimal.Decimal(input_value), locale='en_US', decimal_quantization=False) == expected_value
开发者ID:JonathanRRogers,项目名称:babel,代码行数:4,代码来源:test_numbers.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python numbers.parse_decimal函数代码示例发布时间:2022-05-24
下一篇:
Python numbers.format_percent函数代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap