Skip to content

monetary argument to locale.format_string() not working as expected #93669

Closed
@annaraven

Description

@annaraven

The new 3.7+ keyword argument monetary to locale.format_string() does not appear to do anything. Example below:

locale.setlocale(locale.LC_NUMERIC, 'it')
'it'
locale.setlocale(locale.LC_MONETARY, 'it')
'it'
locale.format_string('%d', 100000)
'100000'
locale.format_string('%d', 100000, grouping=True)
'100.000' #groups as expected with Italian thousands separator
locale.format_string('%d', 100000, monetary=True)
'100000' #not the expected result! Expected '100.000,00'
locale.format_string('%d', 100000, grouping=True, monetary=True)
'100.000' #no difference from just "grouping=True"
locale.format_string('%f', 100000, grouping=True, monetary=True)
'100.000,000000' #definitely not the expected result. I expected 2 decimal places.
locale.currency(100000, grouping=True)
'100.000,00 €' # THIS is the expected result, just a sanity check to make sure LC_MONETARY is appropriately set.

Example from: Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32
Similar results on a Mac running macOS Monterey version 12.3.1 and Python 3.10.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions