I have got dosage strength values like 20.5 mg
,20 mg
in string . I want to extract only integer or float value.
Below is what I have tried so far
def parseint(self,string):
return int(''.join([x for x in string if x.isdigit()]))
But this is not working in all cases.
ex1)
parseint('2 mg')
o/p- 2
ex2)
parseint('10.2 mg')
o/p - 102
Expected output:
i/p "20.5 MG" o/p- 20.5
i/p "20.0 MG" o/p - 20.0
i/p "20.0 MG" o/p - 20.0