<commit_before>.. -*- mode: rst; encoding: utf-8 -*-

.. _numbers:

=================
Number Formatting
=================


Support for locale-specific formatting and parsing of numbers is provided by
the ``babel.numbers`` module:

.. code-block:: pycon

    >>> from babel.numbers import format_number, format_decimal, format_percent

Examples:

.. code-block:: pycon

    >>> format_decimal(1.2345, locale='en_US')
    u'1.234'
    >>> format_decimal(1.2345, locale='sv_SE')
    u'1,234'
    >>> format_decimal(12345, locale='de_DE')
    u'12.345'
<commit_msg>Improve number formatting example<commit_after>.. -*- mode: rst; encoding: utf-8 -*-

.. _numbers:

=================
Number Formatting
=================


Support for locale-specific formatting and parsing of numbers is provided by
the ``babel.numbers`` module:

.. code-block:: pycon

    >>> from babel.numbers import format_number, format_decimal, format_percent

Examples:

.. code-block:: pycon

    # Numbers with decimal places
    >>> format_decimal(1.2345, locale='en_US')
    u'1.234'
    >>> format_decimal(1.2345, locale='sv_SE')
    u'1,234'
    # Integers with thousand grouping
    >>> format_decimal(12345, locale='de_DE')
    u'12.345'
    >>> format_decimal(12345678, locale='de_DE')
    u'12.345.678'
{'fraction_non_alphanumeric': 0.18954758190327614, 'fraction_numerical': 0.057722308892355696, 'mean_word_length': 3.9536679536679538, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5238989', 'n_tokens_mistral': 480, 'n_tokens_neox': 409, 'n_words': 98}