Last active
August 12, 2020 05:50
-
-
Save harshitsinghai77/14f907d1e89328b90c6aa220e83c1869 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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