mirror of
https://github.com/bblaz/num2words.git
synced 2025-12-06 06:42:25 +00:00
[FIX] lang_LT, lang_LV: negative amounts (#185)
Negative amounts were not working (when no currency is used), because `get_digits` method does not expect `-` sign, which crashes conversion. To avoid that, we split minus sign from number string and prepare its word to be used with amount words. closes: #184
This commit is contained in:
committed by
Istvan SZALAÏ
parent
1ca8225ea6
commit
39f522f34a
@@ -89,6 +89,13 @@ class Num2Word_Base(object):
|
||||
|
||||
return out
|
||||
|
||||
def parse_minus(self, num_str):
|
||||
"""Detach minus and return it as symbol with new num_str."""
|
||||
if num_str.startswith('-'):
|
||||
# Extra spacing to compensate if there is no minus.
|
||||
return '%s ' % self.negword, num_str[1:]
|
||||
return '', num_str
|
||||
|
||||
def to_cardinal(self, value):
|
||||
try:
|
||||
assert int(value) == value
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA
|
||||
# TODO: replace WINDOWS line endings to UNIX?
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from .base import Num2Word_Base
|
||||
@@ -98,15 +99,17 @@ class Num2Word_LT(Num2Word_Base):
|
||||
|
||||
def to_cardinal(self, number):
|
||||
n = str(number).replace(',', '.')
|
||||
base_str, n = self.parse_minus(n)
|
||||
if '.' in n:
|
||||
left, right = n.split('.')
|
||||
return '%s %s %s' % (
|
||||
return '%s%s %s %s' % (
|
||||
base_str,
|
||||
self._int2word(int(left)),
|
||||
self.pointword,
|
||||
self._int2word(int(right))
|
||||
)
|
||||
else:
|
||||
return self._int2word(int(n))
|
||||
return "%s%s" % (base_str, self._int2word(int(n)))
|
||||
|
||||
def to_ordinal(self, number):
|
||||
raise NotImplementedError()
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA
|
||||
# TODO: replace WINDOWS line endings to UNIX?
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from .base import Num2Word_Base
|
||||
@@ -132,15 +133,17 @@ class Num2Word_LV(Num2Word_Base):
|
||||
|
||||
def to_cardinal(self, number):
|
||||
n = str(number).replace(',', '.')
|
||||
base_str, n = self.parse_minus(n)
|
||||
if '.' in n:
|
||||
left, right = n.split('.')
|
||||
return u'%s %s %s' % (
|
||||
return '%s%s %s %s' % (
|
||||
base_str,
|
||||
self._int2word(int(left)),
|
||||
self.pointword,
|
||||
self._int2word(int(right))
|
||||
)
|
||||
else:
|
||||
return self._int2word(int(n))
|
||||
return "%s%s" % (base_str, self._int2word(int(n)))
|
||||
|
||||
def pluralize(self, n, forms):
|
||||
form = 0 if (n % 10 == 1 and n % 100 != 11) else 1 if n != 0 else 2
|
||||
|
||||
Reference in New Issue
Block a user