Here is an example of code I often see:
import time
def gettime():
return int(round(time.time()*1000))
In this case, what is the reason of using round()
in this code? time.time()
always returns 1-2 digits after the decimal, so round()
function seems useless.
It is not useless, time.time()
in my system returns something like:
1430407063.751232
multiplying by 1000 returns:
1430407063751.232
round
rounds this to 1430407063751.0
, but if it was 1430407063751.532
, it'll round it to 1430407063752.0
.
time.time()
:
Return the time in seconds since the epoch as a floating point number. Note that even though the time is always returned as a floating point number, not all systems provide time with a better precision than 1 second. While this function normally returns non-decreasing values, it can return a lower value than a previous call if the system clock has been set back between the two calls.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With