def atoi(self, str):
# write your code here
str = str.strip()
if (str == ''
or str[0] == '.'
or '-' in str[1:]
or str.count('.') > 1
or '+-' in str
or set(str) & set('0123456789') == set()):
return 0
str = str.strip('+')
for i in range(len(str)):
if str[i] not in '-.0123456789':
str = str[:i]
break
L = str.split('.')
num = int(L[0])
if num >= 2147483647:
return 2147483647
elif num <= -2147483648:
return -2147483648
if len(L) < 2:
return num
tail = int(L[1][0])
if tail < 5:
return num
return num+1