savoirfairelinux / num2words

Modules to convert numbers to words. 42 --> forty-two
GNU Lesser General Public License v2.1
809 stars 483 forks source link

Library don't work with Ukrainian float numbers #579

Closed techn0man1ac closed 2 weeks ago

techn0man1ac commented 1 month ago

Hello.

I have are problem - here simple example:

import num2words 

text = 'Правило Парето, це завжди 70% на 30% - 30.0% це робота а 70.0% - результат'
text = text.replace("%", " %") # 89.9% -> 89.9 %
text = ' '.join([num2words.num2words(i, to='cardinal', lang='uk') if i.isdigit() else i for i in text.split()])

print(text) # Правило Парето, це завжди сімдесят % на тридцять % - 30.0 % це робота а 70.0 % - результат

As you can see, everything works perfectly with integers, but misses floating point numbers.

smilingDima commented 2 weeks ago

"30.0".isdigit() returns False. You can try comething like this:

text = ' '.join([num2words.num2words(i, to='cardinal', lang='uk') if i.replace('.','',1).isdigit() else i for i in text.split()])

The result is: Правило Парето, це завжди сімдесят % на тридцять % - тридцять кома нуль нуль % це робота а сімдесят кома нуль нуль % - результат

techn0man1ac commented 2 weeks ago

"30.0".isdigit() returns False. You can try comething like this:

text = ' '.join([num2words.num2words(i, to='cardinal', lang='uk') if i.replace('.','',1).isdigit() else i for i in text.split()])

The result is: Правило Парето, це завжди сімдесят % на тридцять % - тридцять кома нуль нуль % це робота а сімдесят кома нуль нуль % - результат

Awesome. Thank's.