0

Here is my code

import time
t0=time.clock()
t1=time.clock()
time_difference = t1-t0
print time_difference

and output is

9.99999999998e-07

i want to assign value of t1-t0 to time_difference in float format having 2 digits after decimal how can i do that

2 Answers2

1

If you wish to print the value, you can use formatted output. This will print float values with two decimal digits after the dot: print "%.2f" % time_difference.

If you wish to update time_difference as a float value with two digits, you can use the round function (see https://docs.python.org/2/library/functions.html#round): time_difference = round(time_difference, 2).

anumi
  • 3,794
  • 1
  • 21
  • 22
1

The simplest way to convert an exponential to float is

e_variable = 4.3e-05 

convert_to_float = str('%.08f' % e_variable)

print convert_to_float
B.M
  • 1,752
  • 3
  • 13
  • 18