Skip to content
Advertisement

Arbitrary precision of square roots

I was quite disappointed when decimal.Decimal(math.sqrt(2)) yielded

JavaScript

and the digits after the 15th decimal place turned out wrong. (Despite happily giving you much more than 15 digits!)

How can I get the first m correct digits in the decimal expansion of sqrt(n) in Python?

Advertisement

Answer

Use the sqrt method on Decimal

JavaScript
Advertisement