Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Removing all non-numeric characters from string in Python

# Many right answers but in case you want it in a float, directly, without using regex:

x= '$123.45M'
float(''.join(c for c in x if (c.isdigit() or c =='.'))


#You can change the point for a comma depending on your needs.
#change for this if you know your number is an integer

x='$1123'    
int(''.join(c for c in x if c.isdigit())
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Removing #characters #string #Python
ADD COMMENT
Topic
Name
2+5 =