This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients eric.smith, mark.dickinson, serhiy.storchaka, skrah, steelman, vstinner
Date 2019-01-09.00:51:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1546995119.59.0.0822633599386.issue35638@roundup.psfhosted.org>
In-reply-to
Content
Łukasz Stelmach:
> It is currently impossible to format floating point numbers with an arbitrary number of decimal digits AND the decimal point matching locale settings.

I would like to warn you that handling properly locales can be very tricky. I just wrote an article about that:
https://vstinner.github.io/locale-bugfixes-python3.html


Stefan Krah:
> My main concern with 'm' for libmpdec is that I'd like to reserve it
for LC_MONETARY.

Since it seems like we are still at the "idea" stage, would it make sense to add a function which accept options to choose how to format a number?

* decimal point
* thousands separator
* grouping

Because there are more and more format variants. See for example Python/formatter_unicode.c. It has 5 "locale types":

* LT_NO_LOCALE
* LT_DEFAULT_LOCALE
* LT_UNDERSCORE_LOCALE
* LT_UNDER_FOUR_LOCALE
* LT_CURRENT_LOCALE

and it uses this structure:

/* Locale info needed for formatting integers and the part of floats
   before and including the decimal. Note that locales only support
   8-bit chars, not unicode. */
typedef struct {
    PyObject *decimal_point;
    PyObject *thousands_sep;
    const char *grouping;
    char *grouping_buffer;
} LocaleInfo;

There is the locale but also "underscore" separator for thousands: see PEP 515.

I'm not talking about adding something into format(), but add a method to float maybe. Or add a function somewhere else.

--

By the way, the decimal module doesn't support properly the following corner case: LC_NUMERIC using an encoding different than LC_CTYPE encoding. I wrote https://github.com/python/cpython/pull/5191 but I abandonned my change.
History
Date User Action Args
2019-01-09 00:52:00vstinnersetrecipients: + vstinner, mark.dickinson, eric.smith, skrah, serhiy.storchaka, steelman
2019-01-09 00:51:59vstinnersetmessageid: <1546995119.59.0.0822633599386.issue35638@roundup.psfhosted.org>
2019-01-09 00:51:59vstinnerlinkissue35638 messages
2019-01-09 00:51:59vstinnercreate