Displaying the output of a variable to more than 2 decimal places

后端 未结 4 1538
半阙折子戏
半阙折子戏 2020-12-20 02:14

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         


        
4条回答
  •  天命终不由人
    2020-12-20 02:48

    >>> f = 1/7.
    >>> repr(f)
    '0.14285714285714285'
    >>> str(f)
    '0.142857142857'
    >>> f
    0.14285714285714285
    >>> print f
    0.142857142857
    >>> '%.15f' % f
    '0.142857142857143'
    

提交回复
热议问题