Skip to content

Commit 092eda1

Browse files
committed
Fix faif#247: simplify __str__ in structural/mvc.py
1 parent 4fa515a commit 092eda1

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

structural/mvc.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@ class Price(float):
2727
__str__ functionality."""
2828

2929
def __str__(self):
30-
first_digits_str = str(round(self, 2))
31-
try:
32-
dot_location = first_digits_str.index('.')
33-
except ValueError:
34-
return first_digits_str + '.00'
35-
else:
36-
return first_digits_str + '0' * (3 + dot_location - len(first_digits_str))
30+
return "{:.2f}".format(self)
3731

3832
products = {
3933
'milk': {'price': Price(1.50), 'quantity': 10},

0 commit comments

Comments
 (0)