I have the following code which compares the input value that comes as a string with the one the function constracts. Basically checks the if the number the user enters is correct. The function works but only for 2 decimal points but the user is allowed to enter 2 to 4 decimal digits... How can I construct the right value?
def check_currency(self, amount):
amount = amount.replace("+", "")
amount = amount.replace("-", "")
sInput = amount.replace(",", ".")
locale.setlocale(locale.LC_ALL, self.LANG)
result = locale.currency(float(sInput), symbol=False, grouping=True)
if (amount == result):
return True
else:
return False
PS: The self.LANG get the respective value based on the system that the code runs on.