soupe soupe - 1 year ago 77
SQL Question

Django save scientific number

I'm trying to find a way to format a scientific number and save it into database. My number is read from a csv file.

class Doc(models.Model):

for line in csvfile:
data = Doc()

This following code generate this error:

invalid literal for int() with base 10: '2,02161E+12'

2,02E+12 is the value on csv file when it's read on standart format and 2021610000000 for the number format. I want to store the "2021610000000".
Is there a way to force reading the csv column as number ?

Answer Source

Your data is malformed. While the int('2,02161E+12') and float('2,02161E+12') would indeed produce that error float('2.02161E+12') would not. So the solution is

int( float('2,02161E+12'.replace(',','.)) )
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download