Skip to content

Support comma as decimal marker, spaces as thousands separator #19

Description

@todofixthis

To conform to international standards, the Decimal filter should handle commas and spaces:

From https://en.wikipedia.org/wiki/SI:

The 10th resolution of CGPM in 2003 declared that "the symbol for the decimal marker shall be either the point on the line or the comma on the line." In practice, the decimal point is used in English-speaking countries and most of Asia, and the comma in most of Latin America and in continental European countries.

Spaces should be used as a thousands separator (1 000 000) in contrast to commas or periods (1,000,000 or 1.000.000) to reduce confusion resulting from the variation between these forms in different countries.

Examples:

# Valid
Decimal().apply('0.54')
Decimal().apply('0,54')
Decimal().apply('.54')
Decimal().apply(',54')
Decimal().apply('54.')
Decimal().apply('54,')
Decimal().apply('1 000 000.54')
Decimal().apply('1 000 000,54')

# Not valid - multiple decimal markers
Decimal().apply('0.5.4')
Decimal().apply('0,5,4')
Decimal().apply('2,000.00')

# Not valid - thousands separator used incorrectly
Decimal().apply('1 000 0,0)
Decimal().apply('0,5 4')

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions