{
  "id": "fraction-to-decimal",
  "version": "02ef73cc90db",
  "status": "published",
  "name": "Fraction to Decimal Calculator",
  "question": "How does fraction to decimal work?",
  "summary": "Converts a fraction or mixed number to its exact decimal, with the repeating digits marked, a rounded value, the percent, and the long division.",
  "category": "math",
  "subcategory": "fractions",
  "url": "https://www.acalculator.org/math/fraction-to-decimal",
  "markdown": "https://www.acalculator.org/math/fraction-to-decimal.md",
  "kind": "function",
  "method": "Divide the numerator by the denominator by long division: each step multiplies the remainder by 10 and divides again; the decimal ends when a remainder is 0 and repeats from the first remainder that comes up twice.",
  "assumptions": [
    "The arithmetic is exact, with whole numbers of any size.",
    "A repeating block is marked with a bar over each of its digits (0.16̅ = 0.1666…). If no block repeats within 60 decimal places, the first 60 are shown, then \"…\".",
    "The rounded value keeps exactly the chosen number of decimal places; halves round away from zero (0.125 to 2 places is 0.13)."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "f": {
        "title": "Fraction",
        "description": "A fraction, mixed number, or whole number, such as 5/8, 1 3/4, or -2/3.",
        "type": "string",
        "pattern": "^-?\\d+( \\d+)?(/\\d+)?$"
      },
      "dp": {
        "title": "Round to (decimal places)",
        "description": "How many decimal places the rounded value keeps, from 0 to 20.",
        "type": "integer",
        "minimum": 0,
        "maximum": 20
      }
    }
  },
  "outputs": {
    "decimal": {
      "label": "Decimal",
      "description": "The exact decimal: every digit when it ends, or the repeating digits marked with a bar (0.16̅ is 0.1666…).",
      "format": "text"
    },
    "rounded": {
      "label": "Rounded",
      "description": "The decimal rounded to the chosen number of decimal places; halves round away from zero.",
      "format": "text"
    },
    "percent": {
      "label": "As a percent",
      "description": "The fraction times 100, exact, with the same bar for repeating digits.",
      "format": "text"
    },
    "kind": {
      "label": "Type of decimal",
      "description": "Terminating when the digits end, repeating when a block of digits repeats forever.",
      "format": "text"
    },
    "period": {
      "label": "Repeating digits",
      "description": "How many digits the repeating block has, when it is found within 60 decimal places.",
      "format": "integer"
    },
    "fractionText": {
      "label": "Fraction in lowest terms",
      "description": "The fraction as an improper fraction in lowest terms, numerator/denominator.",
      "format": "text"
    },
    "steps": {
      "label": "Long division",
      "description": "The long division of the numerator by the denominator, one digit at a time.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "f": "5/8",
      "dp": 4
    },
    "outputs": {
      "decimal": "0.625",
      "rounded": "0.6250",
      "percent": "62.5%",
      "kind": "terminating",
      "period": 0,
      "fractionText": "5/8",
      "steps": "5 ÷ 8 = 0 remainder 5; 50 ÷ 8 = 6 remainder 2; 20 ÷ 8 = 2 remainder 4; 40 ÷ 8 = 5 remainder 0; The remainder is 0, so the decimal ends; 5/8 = 0.625"
    },
    "text": "5/8 as a decimal is 0.625."
  },
  "examples": [
    {
      "given": {
        "f": "5/8",
        "dp": 4
      },
      "expect": {
        "decimal": "0.625",
        "rounded": "0.6250",
        "percent": "62.5%",
        "kind": "terminating",
        "period": 0,
        "steps": "5 ÷ 8 = 0 remainder 5; 50 ÷ 8 = 6 remainder 2; 20 ÷ 8 = 2 remainder 4; 40 ÷ 8 = 5 remainder 0; The remainder is 0, so the decimal ends; 5/8 = 0.625"
      },
      "source": "hand calculation in content.mdx (long division); Python 3: 5 / 8 = 0.625; method from OpenStax Prealgebra 2e, section 5.3: https://openstax.org/books/prealgebra-2e/pages/5-3-decimals-and-fractions"
    },
    {
      "given": {
        "f": "1/3",
        "dp": 4
      },
      "expect": {
        "decimal": "0.3̅",
        "rounded": "0.3333",
        "percent": "33.3̅%",
        "kind": "repeating",
        "period": 1
      },
      "source": "hand calculation in content.mdx: 10 ÷ 3 = 3 remainder 1 again and again"
    },
    {
      "given": {
        "f": "1/6",
        "dp": 2
      },
      "expect": {
        "decimal": "0.16̅",
        "rounded": "0.17",
        "period": 1
      },
      "source": "hand calculation in content.mdx: 1 ÷ 6 = 0.1666…; the 6 repeats"
    },
    {
      "given": {
        "f": "1/7",
        "dp": 3
      },
      "expect": {
        "decimal": "0.1̅4̅2̅8̅5̅7̅",
        "rounded": "0.143",
        "period": 6
      },
      "source": "hand calculation in content.mdx: the remainders 1, 3, 2, 6, 4, 5 then 1 again; Python 3: 1/7 = 0.14285714285714285"
    },
    {
      "given": {
        "f": "1 3/4",
        "dp": 1
      },
      "expect": {
        "decimal": "1.75",
        "rounded": "1.8",
        "fractionText": "7/4",
        "percent": "175%"
      },
      "source": "hand calculation in content.mdx: 1 3/4 = 7/4 = 1.75; 1.75 is halfway, so it rounds away from zero to 1.8"
    },
    {
      "given": {
        "f": "-2/3",
        "dp": 4
      },
      "expect": {
        "decimal": "-0.6̅",
        "rounded": "-0.6667"
      },
      "source": "hand calculation in content.mdx: 2 ÷ 3 = 0.666…, with the minus sign"
    },
    {
      "given": {
        "f": "1/97"
      },
      "expect": {
        "decimal": "0.010309278350515463917525773195876288659793814432989690721649…",
        "kind": "repeating"
      },
      "source": "hand calculation in content.mdx: 1/97 repeats every 96 digits, more than 60; Python 3: str(10**60 // 97) gives the first 60 decimals"
    }
  ],
  "sources": [
    "OpenStax, Prealgebra 2e, section 5.3 Decimals and Fractions (converting fractions to decimals, repeating decimals): https://openstax.org/books/prealgebra-2e/pages/5-3-decimals-and-fractions",
    "G. H. Hardy and E. M. Wright, An Introduction to the Theory of Numbers, sections 9.1 to 9.6 (terminating and recurring decimals)"
  ],
  "related": [
    "fraction",
    "simplify-fraction",
    "decimal-to-fraction",
    "mixed-numbers",
    "rounding"
  ],
  "changelog": []
}
