mirror of
https://github.com/bblaz/num2words.git
synced 2025-12-06 06:42:25 +00:00
Merge pull request #223 from btharper/strings
Convert strings to Decimal values
This commit is contained in:
@@ -101,6 +101,8 @@ def num2words(number, ordinal=False, lang='en', to='cardinal', **kwargs):
|
||||
if lang not in CONVERTER_CLASSES:
|
||||
raise NotImplementedError()
|
||||
converter = CONVERTER_CLASSES[lang]
|
||||
if isinstance(number, str):
|
||||
number = converter.str_to_number(number)
|
||||
# backwards compatible
|
||||
if ordinal:
|
||||
return converter.to_ordinal(number)
|
||||
|
||||
@@ -97,6 +97,9 @@ class Num2Word_Base(object):
|
||||
return '%s ' % self.negword, num_str[1:]
|
||||
return '', num_str
|
||||
|
||||
def str_to_number(self, value):
|
||||
return Decimal(value)
|
||||
|
||||
def to_cardinal(self, value):
|
||||
try:
|
||||
assert int(value) == value
|
||||
|
||||
@@ -87,7 +87,7 @@ class CliTestCase(unittest.TestCase):
|
||||
self.assertEqual(output.return_code, 0)
|
||||
self.assertEqual(
|
||||
output.out.strip(),
|
||||
"one hundred and fifty point zero"
|
||||
"one hundred and fifty"
|
||||
)
|
||||
|
||||
def test_cli_with_lang(self):
|
||||
@@ -97,7 +97,7 @@ class CliTestCase(unittest.TestCase):
|
||||
self.assertEqual(output.return_code, 0)
|
||||
self.assertEqual(
|
||||
output.out.strip(),
|
||||
"ciento cincuenta punto cero"
|
||||
"ciento cincuenta"
|
||||
)
|
||||
|
||||
def test_cli_with_lang_to(self):
|
||||
|
||||
Reference in New Issue
Block a user