projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
More cleanup.
[python_utils.git]
/
type
/
centcount.py
diff --git
a/type/centcount.py
b/type/centcount.py
index 2cb99e029ede3a72f3ccb83e79fbfaf62b6cbb15..4529695cd92174fe7e6aaff60df63dcad999d296 100644
(file)
--- a/
type/centcount.py
+++ b/
type/centcount.py
@@
-1,7
+1,10
@@
#!/usr/bin/env python3
#!/usr/bin/env python3
+"""An amount of money (USD) represented as an integral count of
+cents."""
+
import re
import re
-from typing import Optional, Tuple
, TypeVar
+from typing import Optional, Tuple
import math_utils
import math_utils
@@
-36,9
+39,9
@@
class CentCount(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 CentCount(centcount=self.centcount, currency=self.currency)
def __pos__(self):
return CentCount(centcount=self.centcount, currency=self.currency)
@@
-181,8
+184,8
@@
class CentCount(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__)
CENTCOUNT_RE = re.compile(r"^([+|-]?)(\d+)(\.\d+)$")
CURRENCY_RE = re.compile(r"^[A-Z][A-Z][A-Z]$")
CENTCOUNT_RE = re.compile(r"^([+|-]?)(\d+)(\.\d+)$")
CURRENCY_RE = re.compile(r"^[A-Z][A-Z][A-Z]$")