mirror of
https://github.com/bblaz/num2words.git
synced 2025-12-06 06:42:25 +00:00
Merge branch 'iss24' of https://github.com/isnani/num2words into isnani-iss24
This commit is contained in:
@@ -115,17 +115,15 @@ class Num2Word_Base(object):
|
|||||||
raise TypeError(self.errmsg_nonnum % value)
|
raise TypeError(self.errmsg_nonnum % value)
|
||||||
|
|
||||||
pre = int(value)
|
pre = int(value)
|
||||||
post = abs(value - pre)
|
post = str(abs(value - pre) * 10**self.precision)
|
||||||
|
|
||||||
out = [self.to_cardinal(pre)]
|
out = [self.to_cardinal(pre)]
|
||||||
if self.precision:
|
if self.precision:
|
||||||
out.append(self.title(self.pointword))
|
out.append(self.title(self.pointword))
|
||||||
|
|
||||||
for i in range(self.precision):
|
for i in range(self.precision):
|
||||||
post *= 10
|
curr = int(post[i])
|
||||||
curr = int(post)
|
|
||||||
out.append(str(self.to_cardinal(curr)))
|
out.append(str(self.to_cardinal(curr)))
|
||||||
post -= curr
|
|
||||||
|
|
||||||
return " ".join(out)
|
return " ".join(out)
|
||||||
|
|
||||||
|
|||||||
@@ -21,3 +21,10 @@ class Num2WordsENTest(TestCase):
|
|||||||
def test_and_join_199(self):
|
def test_and_join_199(self):
|
||||||
# ref https://github.com/savoirfairelinux/num2words/issues/8
|
# ref https://github.com/savoirfairelinux/num2words/issues/8
|
||||||
self.assertEqual(num2words(199), "one hundred and ninety-nine")
|
self.assertEqual(num2words(199), "one hundred and ninety-nine")
|
||||||
|
|
||||||
|
def test_cardinal_for_float_number(self):
|
||||||
|
# issue 24
|
||||||
|
self.assertEqual(num2words(12.50), "twelve point five zero")
|
||||||
|
self.assertEqual(num2words(12.51), "twelve point five one")
|
||||||
|
self.assertEqual(num2words(12.53), "twelve point five three")
|
||||||
|
self.assertEqual(num2words(12.59), "twelve point five nine")
|
||||||
Reference in New Issue
Block a user