projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Preformatted box that doesn't wrap the contents.
[python_utils.git]
/
type
/
money.py
diff --git
a/type/money.py
b/type/money.py
index 39557aacdf79dc31ca6e48d27f367305325e80b8..99637d1f23bd607c8856f4fada204b1859c51f3d 100644
(file)
--- a/
type/money.py
+++ b/
type/money.py
@@
-1,8
+1,12
@@
#!/usr/bin/env python3
#!/usr/bin/env python3
+# © Copyright 2021-2022, Scott Gasch
+
+"""A class to represent money. See also centcount.py"""
+
import re
from decimal import Decimal
import re
from decimal import Decimal
-from typing import Optional, Tuple
, TypeVar
+from typing import Optional, Tuple
import math_utils
import math_utils
@@
-39,9
+43,9
@@
class Money(object):
a = round(a, 2)
s = f'{a:,.2f}'
if self.currency is not None:
a = round(a, 2)
s = f'{a:,.2f}'
if self.currency is not None:
- return
'%s %s' % (s, self.currency)
+ return
f'{s} {self.currency}'
else:
else:
- return
'$%s' % s
+ return
f'${s}'
def __pos__(self):
return Money(amount=self.amount, currency=self.currency)
def __pos__(self):
return Money(amount=self.amount, currency=self.currency)
@@
-178,8
+182,8
@@
class Money(object):
def __ge__(self, other):
return self > other or self == other
def __ge__(self, other):
return self > other or self == other
- def __hash__(self):
- return
self.__repr__
+ def __hash__(self)
-> int
:
+ return
hash(self.__repr__)
AMOUNT_RE = re.compile(r"^([+|-]?)(\d+)(\.\d+)$")
CURRENCY_RE = re.compile(r"^[A-Z][A-Z][A-Z]$")
AMOUNT_RE = re.compile(r"^([+|-]?)(\d+)(\.\d+)$")
CURRENCY_RE = re.compile(r"^[A-Z][A-Z][A-Z]$")