[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-util] branch master updated: fix infinite loop in stringify
From: |
gnunet |
Subject: |
[taler-taler-util] branch master updated: fix infinite loop in stringify and add test case |
Date: |
Wed, 18 Dec 2019 21:24:38 +0100 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository taler-util.
The following commit(s) were added to refs/heads/master by this push:
new 7641c1a fix infinite loop in stringify and add test case
7641c1a is described below
commit 7641c1a66caf87858255320d88673223f0dd1f31
Author: Florian Dold <address@hidden>
AuthorDate: Wed Dec 18 21:23:13 2019 +0100
fix infinite loop in stringify and add test case
Also bump to 0.6.2
---
setup.py | 2 +-
taler/util/amount.py | 7 ++++---
tests/test_amount.py | 1 +
3 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/setup.py b/setup.py
index bd5ff09..c9b7d20 100644
--- a/setup.py
+++ b/setup.py
@@ -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')
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-taler-util] branch master updated: fix infinite loop in stringify and add test case,
gnunet <=