Print extremely large long in scientific notation in python

后端 未结 4 2090
长发绾君心
长发绾君心 2021-02-07 13:18

Is there a way to get python to print extremely large longs in scientific notation? I am talking about numbers on the order of 10^1000 or larger, at this size the standard print

4条回答
  •  一向
    一向 (楼主)
    2021-02-07 13:38

    Here's a solution using only standard library:

    >>> import decimal
    >>> x = 10 ** 1000
    >>> d = decimal.Decimal(x)
    >>> format(d, '.6e')
    '1.000000e+1000' 
    

提交回复
热议问题