author Sybren A. Stüvel Tue, 26 Mar 2019 10:56:53 +0000 (11:56 +0100) committer Sybren A. Stüvel Tue, 26 Mar 2019 10:56:53 +0000 (11:56 +0100)

@@ -80,13 +80,19 @@ class Money:
"""Return the amount as string with currency symbol, so '€' instead of 'EUR'."""
return f'{self.currency_symbol}\u00A0{self.decimals_string}'

"""Return the amount as string with currency symbol, so '€' instead of 'EUR'."""
return f'{self.currency_symbol}\u00A0{self.decimals_string}'

+    def with_currency_symbol_rounded(self) -> str:
+        """Same as with_currency_symbol() rounding to entire units."""
+
+        whole_rounded = int(round(self._cents / 100))
+        return f'{self.currency_symbol}\u00A0{whole_rounded}'
+
def with_currency_symbol_nonocents(self) -> str:
"""Same as with_currency_symbols but never ends in '.00'."""

def with_currency_symbol_nonocents(self) -> str:
"""Same as with_currency_symbols but never ends in '.00'."""

-        cents = self.just_cents
+        whole, cents = divmod(self._cents, 100)
if cents:
if cents:
-            return self.with_currency_symbol()
-        return f'{self.currency_symbol}\u00A0{self.just_whole}'
+            return f'{self.currency_symbol}\u00A0{whole}.{cents:02}'
+        return f'{self.currency_symbol}\u00A0{whole}'

def __pos__(self) -> 'Money':
return Money(self._currency, self._cents)

def __pos__(self) -> 'Money':
return Money(self._currency, self._cents)
@@ -160,6 +160,14 @@ class BasicOperationsTest(TestCase):
self.assertEqual('\$\u00A010.50', USD(1050).with_currency_symbol_nonocents())
self.assertEqual('¥\u00A00.99', Money('JPY', 99).with_currency_symbol_nonocents())

self.assertEqual('\$\u00A010.50', USD(1050).with_currency_symbol_nonocents())
self.assertEqual('¥\u00A00.99', Money('JPY', 99).with_currency_symbol_nonocents())

+    def test_with_currency_symbol_rounded(self) -> None:
+        self.assertEqual('€\u00A010', EUR(1000).with_currency_symbol_rounded())
+        self.assertEqual('\$\u00A010', USD(1050).with_currency_symbol_rounded())
+        self.assertEqual('\$\u00A011', USD(1051).with_currency_symbol_rounded())
+        self.assertEqual('\$\u00A011', USD(1149).with_currency_symbol_rounded())
+        self.assertEqual('\$\u00A012', USD(1150).with_currency_symbol_rounded())
+        self.assertEqual('¥\u00A01', Money('JPY', 99).with_currency_symbol_rounded())
+

class SumTest(TestCase):
def test_empty(self) -> None:

class SumTest(TestCase):
def test_empty(self) -> None:
@@ -35,7 +35,7 @@
.transform-flip-h.d-flex
span.d-block.d-md-none
strong Current Income
.transform-flip-h.d-flex
span.d-block.d-md-none
strong Current Income
-                                       | {{ summed_income.with_currency_symbol_nonocents }} / month
+                                       | {{ summed_income.with_currency_symbol_rounded }} / month

.progress-label.target(title="Next Milestone")
| #[strong 5 Developers] #[span {{currency_symbol}}&nbsp;{{thermo_mid}}k / month]

.progress-label.target(title="Next Milestone")
| #[strong 5 Developers] #[span {{currency_symbol}}&nbsp;{{thermo_mid}}k / month]