mirror of
https://github.com/bblaz/num2words.git
synced 2025-12-06 06:42:25 +00:00
Fix lang_IT handling of floats (#143)
`n % 1 != 0` is not a valid test for float: In []: 1.1 % 1 == 0 Out[]: False but: In []: 1.0 % 1 == 0 Out[]: True hence it's really necessary to explicitly test for type in this case.
This commit is contained in:
committed by
Ernesto Rodriguez Ortiz
parent
8ffdc5e49d
commit
efce631944
@@ -169,7 +169,7 @@ class Num2Word_IT:
|
||||
def to_cardinal(self, number):
|
||||
if number < 0:
|
||||
string = Num2Word_IT.MINUS_PREFIX_WORD + self.to_cardinal(-number)
|
||||
elif number % 1 != 0:
|
||||
elif isinstance(number, float):
|
||||
string = self.float_to_words(number)
|
||||
elif number < 20:
|
||||
string = CARDINAL_WORDS[number]
|
||||
|
||||
@@ -22,7 +22,6 @@ from num2words import num2words
|
||||
|
||||
|
||||
class Num2WordsITTest(TestCase):
|
||||
|
||||
maxDiff = None
|
||||
|
||||
def test_negative(self):
|
||||
@@ -225,3 +224,11 @@ class Num2WordsITTest(TestCase):
|
||||
"novecentouno miliardi, duecentotrentaquattro milioni e "
|
||||
"cinquecentosessantasettemilaottocentonovantesimo"
|
||||
)
|
||||
|
||||
def test_with_decimals(self):
|
||||
self.assertAlmostEqual(
|
||||
num2words(1.0, lang="it"), "uno virgola zero"
|
||||
)
|
||||
self.assertAlmostEqual(
|
||||
num2words(1.1, lang="it"), "uno virgola uno"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user