[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:
Andrius Laukavičius
2018-08-23 17:39:03 +03:00
committed by Istvan SZALAÏ
parent 1ca8225ea6
commit 39f522f34a
5 changed files with 33 additions and 4 deletions

View File

@@ -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

View File

@@ -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()

View File

@@ -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