4

I have a very silly question, suppose if i have a number 1.70000043572e-05 how should I convert it into float i.e. 0.0000170000043572.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
U-571
  • 519
  • 2
  • 7
  • 23

2 Answers2

10

You need to convert to a float and use str.format specifying the precision:

 In [41]: print "{:f}".format(float("1.70000043572e-05"))
 0.000017

# 16 digits 
In [38]: print "{:.16f}".format(float("1.70000043572e-05"))
0.0000170000043572

Just calling float would give 1.70000043572e-05.

Using older style formatting:

In [45]: print( "%.16f" % float("1.70000043572e-05"))
0.0000170000043572
Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321
5

If you are just inputting the number into your script python will understand that as a float.

If it is a string then use the builtin float on it to do the conversion for example:

x = float("0.423423e4")
print "%.2f" % (x)

will output

4234.23
Simon Gibbons
  • 6,969
  • 1
  • 21
  • 34