{
  "id": "pi",
  "version": "94f50cd64679",
  "status": "published",
  "name": "Pi Calculator",
  "question": "What is pi to many decimal places?",
  "summary": "Gives π (pi) to any number of decimal places up to 1,000 with Machin’s formula, the digit at any place, and the Leibniz series approximation of π to n terms with its error.",
  "category": "math",
  "subcategory": "arithmetic",
  "url": "https://www.acalculator.org/math/pi-calculator",
  "markdown": "https://www.acalculator.org/math/pi-calculator.md",
  "kind": "function",
  "method": "π = 16 arctan(1/5) − 4 arctan(1/239) (Machin), with arctan x = x − x³/3 + x⁵/5 − …; Leibniz: π ≈ 4 × (1 − 1/3 + 1/5 − … ± 1/(2n − 1)).",
  "assumptions": [
    "Digits are cut off (not rounded) after the places you ask for; the rounded value is shown too.",
    "Machin’s series is summed in whole numbers with 10 extra digits, so every digit shown up to 1,000 places is correct."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "show": {
        "title": "Show",
        "description": "π to a number of decimal places, or the Leibniz series approximation.",
        "type": "string",
        "enum": [
          "digits",
          "leibniz"
        ]
      },
      "n": {
        "title": "Decimal places",
        "description": "How many digits after the decimal point, from 1 to 1,000.",
        "type": "integer",
        "minimum": 1,
        "maximum": 1000
      },
      "terms": {
        "title": "Terms",
        "description": "How many terms of the Leibniz series to add, from 1 to 1,000,000.",
        "type": "integer",
        "minimum": 1,
        "maximum": 1000000
      }
    }
  },
  "outputs": {
    "value": {
      "label": "π",
      "description": "π cut off after the decimal places asked for (digits mode), or the series sum (series mode).",
      "format": "text"
    },
    "rounded": {
      "label": "Rounded",
      "description": "π rounded half up to the decimal places asked for.",
      "format": "text"
    },
    "digit": {
      "label": "Digit at that place",
      "description": "The last decimal digit shown: the digit at the place asked for.",
      "format": "integer"
    },
    "approx": {
      "label": "Series sum",
      "description": "4 × (1 − 1/3 + 1/5 − 1/7 + …) to the number of terms.",
      "format": "number"
    },
    "error": {
      "label": "Error (sum − π)",
      "description": "How far the series sum is from π.",
      "format": "number"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "show": "digits",
      "n": 10,
      "terms": 1000
    },
    "outputs": {
      "value": "3.1415926535",
      "rounded": "3.1415926536",
      "digit": 5
    },
    "text": "π = 3.1415926535"
  },
  "examples": [
    {
      "given": {
        "show": "digits",
        "n": 10
      },
      "expect": {
        "value": "3.1415926535",
        "rounded": "3.1415926536",
        "digit": 5
      },
      "source": "Wolfram MathWorld, Machin's Formula (π/4 = 4 arctan(1/5) − arctan(1/239)). https://mathworld.wolfram.com/MachinsFormula.html; Python 3 documentation, decimal module, Recipes: pi() (computes π to the current precision). https://docs.python.org/3/library/decimal.html; π = 3.141592653589…"
    },
    {
      "given": {
        "show": "digits",
        "n": 50
      },
      "expect": {
        "value": "3.1415926535 8979323846 2643383279 5028841971 6939937510",
        "digit": 0,
        "rounded": "3.1415926535 8979323846 2643383279 5028841971 6939937511"
      },
      "source": "Wolfram MathWorld, Machin's Formula (π/4 = 4 arctan(1/5) − arctan(1/239)). https://mathworld.wolfram.com/MachinsFormula.html; Python 3 documentation, decimal module, Recipes: pi() (computes π to the current precision). https://docs.python.org/3/library/decimal.html (decimal pi() at 60 digits: 3.1415926535897932384626433832795028841971693993751058…)"
    },
    {
      "given": {
        "show": "digits",
        "n": 2
      },
      "expect": {
        "value": "3.14",
        "rounded": "3.14",
        "digit": 4
      },
      "source": "Wolfram MathWorld, Machin's Formula (π/4 = 4 arctan(1/5) − arctan(1/239)). https://mathworld.wolfram.com/MachinsFormula.html; hand calculation in content.mdx: 3.14159… cut after 2 places is 3.14"
    },
    {
      "given": {
        "show": "leibniz",
        "terms": 4
      },
      "expect": {
        "approx": 2.895238095238095,
        "error": -0.24635455835169795
      },
      "source": "OpenStax, Calculus Volume 2, §6.4 Working with Taylor Series, Table 6.1 (arctan x = Σ (−1)ⁿ x²ⁿ⁺¹ ÷ (2n + 1) for −1 ≤ x ≤ 1). https://openstax.org/books/calculus-volume-2/pages/6-4-working-with-taylor-series (arctan 1 = π/4); hand calculation in content.mdx: 4 × (1 − 1/3 + 1/5 − 1/7) = 304/105 = 2.8952"
    },
    {
      "given": {
        "show": "leibniz",
        "terms": 1000
      },
      "expect": {
        "approx": 3.140592653839793
      },
      "source": "OpenStax, Calculus Volume 2, §6.4 Working with Taylor Series, Table 6.1 (arctan x = Σ (−1)ⁿ x²ⁿ⁺¹ ÷ (2n + 1) for −1 ≤ x ≤ 1). https://openstax.org/books/calculus-volume-2/pages/6-4-working-with-taylor-series; Python 3 Fraction sum of 4 Σ (−1)ᵏ ÷ (2k + 1), k = 0 … 999 = 3.140592653839793",
      "tolerance": 1e-13
    }
  ],
  "sources": [
    "OpenStax, Calculus Volume 2, §6.4 Working with Taylor Series, Table 6.1 (the Maclaurin series of arctan x, for −1 ≤ x ≤ 1). https://openstax.org/books/calculus-volume-2/pages/6-4-working-with-taylor-series (retrieved 2026-10-02)",
    "Wolfram MathWorld, Machin's Formula (π/4 = 4 arctan(1/5) − arctan(1/239)). https://mathworld.wolfram.com/MachinsFormula.html (retrieved 2026-10-02)",
    "Python 3 documentation, decimal — Decimal fixed-point and floating-point arithmetic, Recipes, pi() (an independent check of the digits). https://docs.python.org/3/library/decimal.html (retrieved 2026-10-02)"
  ],
  "related": [
    "circle",
    "circumference",
    "area-of-a-circle",
    "series"
  ],
  "changelog": []
}
