mirror of
https://github.com/bblaz/num2words.git
synced 2025-12-06 06:42:25 +00:00
address issue 24: floating point spelling
This commit is contained in:
@@ -116,16 +116,15 @@ class Num2Word_Base(object):
|
||||
|
||||
pre = int(value)
|
||||
post = abs(value - pre)
|
||||
post *= 10**self.precision
|
||||
|
||||
out = [self.to_cardinal(pre)]
|
||||
if self.precision:
|
||||
out.append(self.title(self.pointword))
|
||||
|
||||
for i in range(self.precision):
|
||||
post *= 10
|
||||
curr = int(post)
|
||||
out.append(str(self.to_cardinal(curr)))
|
||||
post -= curr
|
||||
curr = str(post)[i]
|
||||
out.append(str(self.to_cardinal(int(curr))))
|
||||
|
||||
return " ".join(out)
|
||||
|
||||
|
||||
@@ -21,3 +21,10 @@ class Num2WordsENTest(TestCase):
|
||||
def test_and_join_199(self):
|
||||
# ref https://github.com/savoirfairelinux/num2words/issues/8
|
||||
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