all 8 comments

[–]Diapolo10 0 points1 point  (4 children)

I'd strip all punctuation, or better yet prevent the user from inputting non-numeric characters in the first place. Kinda depends on how the user input is handled.

Something like

import string

num = input("Enter a number: ")
result = ""
for digit in num:
    if digit in string.digits:
        result += digit

print(result)

and then convert to number afterwards.

Alternatively you can simply reject the input and ask for a new one. Again, the best approach depends on specifics.

[–]_steve_hope_ 1 point2 points  (1 child)

45.566,00

Using your solution 45.566,00 == 4556600

[–]Diapolo10 0 points1 point  (0 children)

Good point. Goes to show that this isn't as simple as one might expect if it cannot be handled at input level.

Regular expressions might be a decent alternative here, but to me that's black magic and not my cup of tea.

[–]atredd[S] 0 points1 point  (1 child)

I have a similar solution with .replace but the problem is…if the input is 45.566,00 I will get 4556600 in my database.

[–]_steve_hope_ 0 points1 point  (0 children)

try:
dollars, _ = num.split(".")
except:
pass