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
  • 45,811
  • 27
  • 120
  • 136
U-571
  • 499
  • 2
  • 7
  • 23

2 Answers2

9

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
  • 168,988
  • 22
  • 228
  • 312
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,693
  • 1
  • 20
  • 34