0

I have a string as follows '$123,456.12'. i want to get rhe value integer value of the string 123456.

I have tried using this function

int(''.join(list(filter(str.isdigit, number))))

but it returns 12345612.

Is there any other solution ?

2 Answers2

2
data = '$123,456.12'

print (int(''.join(list(filter(str.isdigit, data.split('.')[0])))))
# or
print (int(''.join(i for i in data.split('.')[0] if i.isdigit())))

output:

123456
ncica
  • 6,737
  • 1
  • 14
  • 33
1
x = '$123,456.12'
end = x.index('.')
int(x[1:end].replace(',', '')) 
ComplicatedPhenomenon
  • 3,863
  • 2
  • 14
  • 39