gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-bank] branch master updated: pretty amount


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] branch master updated: pretty amount
Date: Wed, 13 Dec 2017 17:56:29 +0100

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository bank.

The following commit(s) were added to refs/heads/master by this push:
     new 5475349  pretty amount
5475349 is described below

commit 547534954f1ef1fbef5bafd6dc653b890a6bd822
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed Dec 13 17:56:06 2017 +0100

    pretty amount
---
 talerbank/app/amount.py | 13 ++++++++-----
 talerbank/app/views.py  |  4 ++--
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/talerbank/app/amount.py b/talerbank/app/amount.py
index 5e1f68c..a36b880 100644
--- a/talerbank/app/amount.py
+++ b/talerbank/app/amount.py
@@ -119,15 +119,18 @@ class Amount:
 
     # Dump string from this amount, will put 'ndigits' numbers
     # after the dot.
-    def stringify(self, ndigits: int) -> str:
+    def stringify(self, ndigits: int, pretty=False) -> str:
         assert ndigits > 0
         ret = '%s:%s.' % (self.currency, str(self.value))
-        fraction = self.fraction
+        tmp = self.fraction
+        fraction_str = ""
         while ndigits > 0:
-            ret += str(int(fraction / (Amount._fraction() / 10)))
-            fraction = (fraction * 10) % (Amount._fraction())
+            fraction_str += str(int(tmp / (Amount._fraction() / 10)))
+            tmp = (tmp * 10) % (Amount._fraction())
             ndigits -= 1
-        return ret
+        if not pretty:
+            return "%s:%d.%s" % (self.currency, self.value, fraction_str)
+        return "%d.%s %s" % (self.value, fraction_str, self.currency)
 
     # Dump the Taler-compliant 'dict' amount
     def dump(self) -> dict:
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index 49890cb..8e6351b 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -136,7 +136,7 @@ def profile_page(request):
 
     context = dict(
         name=user_account.user.username,
-        balance=user_account.amount.stringify(settings.TALER_DIGITS),
+        balance=user_account.amount.stringify(settings.TALER_DIGITS, 
pretty=True),
         sign="-" if user_account.debit else "",
         precision=settings.TALER_DIGITS,
         currency=user_account.amount.currency,
@@ -334,7 +334,7 @@ def extract_history(account):
             cancelled=item.cancelled,
             reimburses=item.reimburses,
             sign=sign,
-            amount=item.amount.stringify(settings.TALER_DIGITS),
+            amount=item.amount.stringify(settings.TALER_DIGITS, pretty=True),
             counterpart=counterpart.account_no,
             counterpart_username=counterpart.user.username,
             subject=item.subject,

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]