Last active
July 25, 2025 12:20
-
-
Save thangarajan8/16c6ec4bb150dbdc5346a4d88e373d92 to your computer and use it in GitHub Desktop.
to be delete
This file contains hidden or 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
def clean_amount(value): | |
# Move trailing minus to the front | |
value = value.replace('-', '') | |
is_negative = value.endswith('-') or value.startswith('-') | |
# Remove thousand separator and convert decimal separator | |
value = value.replace('.', '').replace(',', '.').replace('-', '') | |
# Convert to float | |
try: | |
num = float(value) | |
return -num if is_negative else num | |
except ValueError: | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment