Skip to content

Instantly share code, notes, and snippets.

@harshitsinghai77
Last active August 12, 2020 05:50
Show Gist options
  • Save harshitsinghai77/14f907d1e89328b90c6aa220e83c1869 to your computer and use it in GitHub Desktop.
Save harshitsinghai77/14f907d1e89328b90c6aa220e83c1869 to your computer and use it in GitHub Desktop.
class Decimal:
def __init__(self, number, places):
self.number = number
self.places = places
def __repr__(self):
return "%.{}f".format(self.places) % self.number
class Currency(Decimal):
def __init__(self, symbol, number, places):
super().__init__(number, places)
self.symbol = symbol
def __repr__(self):
return "{}{}".format(self.symbol, super().__repr__())
dec = Decimal(15.682112, 4)
curr = Currency('£', 17.8911, 2)
print(dec)
print(curr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment