I\'m trying to display the output of my addition to more than 2 decimal places.
import time
import random
max_number = 1000000.0
random_time = random.randra
You'll find that if you hard-code the number of digits to print, you'll sometimes get too few or worse yet go past the floating-point precision and get meaningless digits at the end. The standard floating point number only has precision to about 15 digits. You can find out how many of those digits are to the right of the decimal point with this simple formula:
digits_right = 14 - int(math.log10(value))
Using that you can create an appropriate %f format:
fmt = '%%0.%df' % max(0, digits_right)