Skip to content

Spanish decimal separator bug detected #122

@CarlosUriass

Description

@CarlosUriass

Support both , and . as decimal separators in Spanish

Description

According to the Real Academia Española (RAE), both the comma (,) and the dot (.) are valid decimal separators in Spanish. However, the current implementation only supports the comma.

Reference

The ISO 31-0 standard and the General Conference on Weights and Measures initially recommended the comma as the decimal separator. However, in 2003, they acknowledged that using a dot is common in certain regions and accepted both symbols.

  • Geographical distribution:
    • The comma (,) is used in Spain, Argentina, Colombia, Peru, etc.
    • The dot (.) is preferred in Mexico, Guatemala, Venezuela, and among Spanish speakers in the U.S.
    • Some countries (Bolivia, Costa Rica, Cuba, etc.) use both.

To promote standardization, the RAE recommends using the dot (.) as the decimal separator.
Source (RAE)

Expected Behavior

Both "tres coma catorce" → 3.14 and "tres punto catorce" → 3.14 should be correctly parsed as numbers.


Initial Attempt

I modified the Spanish language class in spanish,py to allow both , and . as decimal separators:

class Spanish(Language): MULTIPLIERS = MULTIPLIERS UNITS = UNITS STENS = STENS MTENS = MTENS MTENS_WSTENS = MTENS_WSTENS HUNDRED = HUNDRED NUMBERS = NUMBERS SIGN = {"mas": "+", "menos": "-"} ZERO = {"cero"} DECIMAL_SEP = "coma, punto" # Support both comma and dot DECIMAL_SYM = "."

This works correctly for most numbers, but "uno" is not converted to "1" when followed by a decimal separator.

Current Issue

After modifying the Spanish language class to support both , and . as decimal separators, most cases work correctly. However, there is an issue when "uno" (1) appears before a decimal.

Example of the Bug

print(alpha2digit("uno coma uno", "es")) # Expected: "1.1"  # Got: "uno 0.1"  print(alpha2digit("uno punto dos tres seis", "es")) # Expected: "1.236"  # Got: "uno 0.2 3 6"

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions