diff options
-rw-r--r-- | setup.py | 2 | ||||
-rw-r--r-- | taler/util/amount.py | 7 | ||||
-rwxr-xr-x | tests/test_amount.py | 1 |
3 files changed, 6 insertions, 4 deletions
@@ -25,7 +25,7 @@ with open('README', 'r') as f: setup( name='taler-util', - version='0.6.1', + version='0.6.2', license='LGPL3+', platforms='any', author='Taler Systems SA', diff --git a/taler/util/amount.py b/taler/util/amount.py index c768f30..3891326 100644 --- a/taler/util/amount.py +++ b/taler/util/amount.py @@ -232,7 +232,7 @@ class Amount: # Convert the amount to a string. # # @param self this object. - # @param ndigits how many digits we want for the fractional part. + # @param ndigits minimum number of digits to display in the fractional part # @param pretty if True, put the currency in the last position and # omit the colon. def stringify(self, ndigits=0, pretty=False) -> str: @@ -240,10 +240,11 @@ class Amount: if self.fraction != 0: s += "." frac = self.fraction - while frac != 0 or ndigits != 0: + while frac > 0 or (ndigits is not None and ndigits > 0): s += str(int(frac / (Amount._fraction() / 10))) frac = (frac * 10) % (Amount._fraction()) - ndigits -= 1 + if ndigits > 0: + ndigits -= 1 elif ndigits != 0: s += "." + ("0" * ndigits) if not pretty: diff --git a/tests/test_amount.py b/tests/test_amount.py index 67d9844..a4043b7 100755 --- a/tests/test_amount.py +++ b/tests/test_amount.py @@ -68,3 +68,4 @@ class TestAmount(TestCase): self.assertEqual(self.amount.stringify(3), 'TESTKUDOS:0.000') self.amount.add(Amount('TESTKUDOS', 2, 100)) self.assertEqual(self.amount.stringify(6), 'TESTKUDOS:2.000001') + self.assertEqual(Amount("TESTKUDOS", value=5, fraction=9000000).stringify(), 'TESTKUDOS:5.09') |