Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import datetime
def convert_from_string(number):
nums = number.split(".")
real_num = 0
count = len(nums)
for idx, num in enumerate(nums):
if idx < count - 1:
real_num += int(num) * (1000**(count - idx - 1))
real_num += int(num.split(",")[0]) #assuming we ignore the ","
return real_num
def convert_from_string_to_float(number):
number = str(number)
return float(".".join("".join(number.split(".")).split(",")))
def sanitize(number):
return int(number)
except ValueError:
return convert_from_string(number)
if __name__ == '__main__':
t0 =
print sanitize('120.000') #slowest
print str( - t0)
t0 =
print convert_from_string_to_float(12000) #faster
print str( - t0)
print convert_from_string_to_float('1.200.000')
print sanitize(120000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment