{
  "id": "decimal-to-fraction",
  "version": "97b754461321",
  "status": "published",
  "name": "Decimal to Fraction Converter",
  "question": "How do I convert decimal to fraction?",
  "summary": "Writes a decimal number as an exact fraction in lowest terms, and as a mixed number.",
  "category": "convert",
  "subcategory": "number-bases",
  "url": "https://www.acalculator.org/convert/decimal-to-fraction",
  "markdown": "https://www.acalculator.org/convert/decimal-to-fraction.md",
  "kind": "function",
  "method": "Write the decimal over 10 to the power of its number of decimal places, then divide the numerator and denominator by their greatest common factor.",
  "assumptions": [
    "The decimal is taken exactly as typed: 0.333 is 333/1000, not 1/3.",
    "The decimal keeps up to 17 significant digits, the precision of a number on this page.",
    "A negative decimal gives a negative fraction."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "decimal": {
        "title": "Decimal",
        "description": "The decimal number to write as a fraction, for example 0.625.",
        "type": "number",
        "minimum": -1000000000000,
        "maximum": 1000000000000
      }
    }
  },
  "outputs": {
    "fraction": {
      "label": "Fraction",
      "description": "The decimal as a fraction in lowest terms, numerator over denominator.",
      "format": "text"
    },
    "mixed": {
      "label": "Mixed number",
      "description": "The fraction as a whole number and a proper fraction.",
      "format": "text"
    },
    "work": {
      "label": "How",
      "description": "The decimal over a power of ten, then both parts divided by their greatest common factor.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "decimal": 0.625
    },
    "outputs": {
      "fraction": "5/8",
      "mixed": "5/8",
      "work": "0.625 = 625/1000 = 5/8 (both divided by 125)"
    },
    "text": "0.625 as a fraction is 5/8."
  },
  "examples": [
    {
      "given": {
        "decimal": 0.625
      },
      "expect": {
        "fraction": "5/8",
        "mixed": "5/8",
        "work": "0.625 = 625/1000 = 5/8 (both divided by 125)"
      },
      "source": "hand calculation in content.mdx: 625/1000, divide by 125; Python 3 Fraction(\"0.625\") = 5/8"
    },
    {
      "given": {
        "decimal": 1.25
      },
      "expect": {
        "fraction": "5/4",
        "mixed": "1 1/4"
      },
      "source": "hand calculation in content.mdx: 125/100 = 5/4 = 1 1/4; Python 3 Fraction(\"1.25\") = 5/4"
    },
    {
      "given": {
        "decimal": -0.75
      },
      "expect": {
        "fraction": "-3/4",
        "mixed": "-3/4"
      },
      "source": "hand calculation in content.mdx: 75/100 = 3/4, keep the sign; Python 3 Fraction(\"-0.75\") = -3/4"
    },
    {
      "given": {
        "decimal": 0.3
      },
      "expect": {
        "fraction": "3/10",
        "work": "0.3 = 3/10, already in lowest terms"
      },
      "source": "hand calculation in content.mdx: 3/10 has no common factor; Python 3 Fraction(\"0.3\") = 3/10"
    }
  ],
  "sources": [],
  "related": [
    "binary-to-text"
  ],
  "changelog": []
}
