Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a number in exponential form to decimal form in python [duplicate]

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.

like image 285
U-571 Avatar asked Dec 05 '22 23:12

U-571


1 Answers

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
like image 55
Padraic Cunningham Avatar answered Mar 13 '23 02:03

Padraic Cunningham