Print extremely large long in scientific notation in python

后端 未结 4 2091
长发绾君心
长发绾君心 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:44

    gmpy to the rescue...:

    >>> import gmpy
    >>> x = gmpy.mpf(10**1000)
    >>> x.digits(10, 0, -1, 1)
    '1.e1000'
    

    I'm biased, of course, as the original author and still a committer of gmpy, but I do think it eases tasks such as this one that can be quite a chore without it (I don't know a simple way to do it without some add-on, and gmpy's definitely the add-on I'd choose here;-).

提交回复
热议问题