I need the current time with nanosec.
As string "%.9f" % float_time
it is 1502872986.653693676. You can see 76 at the end.
If I try to write the same time as int int(float_time*10**9)
, it will be 1502872986653693696 and 96 at the end. Why? And which is the right way to get nano format?
from time import time
float_time = time()
print("float_time:", float_time)
int_nano_time = int(float_time*10**9)
print("int_nano_time:", int_nano_time)
str_nano_time = "%.9f" % float_time
print("str_nano_time:", str_nano_time)
float_time: 1502872986.6536937
int_nano_time: 1502872986653693696
str_nano_time: 1502872986.653693676
Solution:
time.monotonic()
float_time: 536596.296
int_nano_time: 536596296000000
str_nano_time: 536596.296000000