Search code examples
pythonmathdecimal-point

how can i show an irrational number to 100 decimal places in python?


I am trying to find the square root of 2 to 100 decimal places, but it only shows to like 10 by default, how can I change this?


Solution

  • decimal module comes in handy.

    >>> from decimal import *
    >>> getcontext().prec = 100
    >>> Decimal(2).sqrt()
    Decimal('1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641573')