Skip to content

Commit

Permalink
Spanish: handle lack of cents part for whole-number currency values
Browse files Browse the repository at this point in the history
  • Loading branch information
bryananderson committed Jan 16, 2025
1 parent 7df3db9 commit 6de47d8
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 9 deletions.
19 changes: 10 additions & 9 deletions num2words/lang_ES.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,18 +389,19 @@ def to_currency(self, val, currency='EUR', cents=True, separator=' con',

# "CENTS" PART (list_result[1])

# Feminine "cents" ("una piastra", "veintiuna piastras"...)
if currency in CENTS_UNA:
if len(list_result) > 1:
# Feminine "cents" ("una piastra", "veintiuna piastras"...)
if currency in CENTS_UNA:

# "una piastra", "veintiuna piastras", "treinta y una piastras"...
list_result[1] = list_result[1].replace("uno", "una")
# "una piastra", "veintiuna piastras", "treinta y una piastras"...
list_result[1] = list_result[1].replace("uno", "una")

# Masc.: Correct orthography for the specific case of "veintiún":
list_result[1] = list_result[1].replace("veintiuno", "veintiún")
# Masc.: Correct orthography for the specific case of "veintiún":
list_result[1] = list_result[1].replace("veintiuno", "veintiún")

# Masculine "cents": general case ("un centavo", "treinta y un
# centavos"...):
list_result[1] = list_result[1].replace("uno", "un")
# Masculine "cents": general case ("un centavo", "treinta y un
# centavos"...):
list_result[1] = list_result[1].replace("uno", "un")

# join back "dollars" part with "cents" part
result = (separator + " ").join(list_result)
Expand Down
Loading

0 comments on commit 6de47d8

Please sign in to comment.