Calculator of Fraction

Fraction Calculator

Add (+) Subtract (-) Multiply (*) Divide (/)
Result:
function gcd(a, b) { return b === 0 ? a : gcd(b, a % b); } function calculateFraction() { var num1 = parseFloat(document.getElementById('numerator1').value); var den1 = parseFloat(document.getElementById('denominator1').value); var operation = document.getElementById('operation').value; var num2 = parseFloat(document.getElementById('numerator2').value); var den2 = parseFloat(document.getElementById('denominator2').value); if (isNaN(num1) || isNaN(den1) || isNaN(num2) || isNaN(den2)) { document.getElementById('fractionResult').innerHTML = "Please enter valid numbers for all fields."; return; } if (den1 === 0 || den2 === 0) { document.getElementById('fractionResult').innerHTML = "Denominator cannot be zero."; return; } var resultNum, resultDen; switch (operation) { case '+': resultNum = (num1 * den2) + (num2 * den1); resultDen = den1 * den2; break; case '-': resultNum = (num1 * den2) – (num2 * den1); resultDen = den1 * den2; break; case '*': resultNum = num1 * num2; resultDen = den1 * den2; break; case '/': if (num2 === 0) { document.getElementById('fractionResult').innerHTML = "Cannot divide by zero (numerator of second fraction is zero)."; return; } resultNum = num1 * den2; resultDen = den1 * num2; break; default: document.getElementById('fractionResult').innerHTML = "Invalid operation selected."; return; } var commonDivisor = gcd(Math.abs(resultNum), Math.abs(resultDen)); var simplifiedNum = resultNum / commonDivisor; var simplifiedDen = resultDen / commonDivisor; if (simplifiedDen < 0) { simplifiedNum = -simplifiedNum; simplifiedDen = -simplifiedDen; } if (simplifiedDen === 1) { document.getElementById('fractionResult').innerHTML = "Result: " + simplifiedNum; } else { document.getElementById('fractionResult').innerHTML = "Result: " + simplifiedNum + "/" + simplifiedDen; } }

Understanding and Calculating Fractions

Fractions are a fundamental concept in mathematics, representing a part of a whole. They consist of two numbers: a numerator (the top number) and a denominator (the bottom number). The numerator tells you how many parts you have, and the denominator tells you how many equal parts make up the whole.

What is a Fraction?

A fraction like 34 means you have 3 parts out of a total of 4 equal parts. For example, if you cut a pizza into 4 slices and eat 3 of them, you've eaten 34 of the pizza.

Operations with Fractions

Our Fraction Calculator allows you to perform the four basic arithmetic operations: addition, subtraction, multiplication, and division.

1. Adding Fractions

To add fractions, they must have a common denominator. If they don't, you find the least common multiple (LCM) of the denominators and convert the fractions. Then, you add the numerators and keep the common denominator. Finally, simplify the result.

Formula: ab + cd = (a × d) + (c × b)(b × d)

Example: 12 + 14

  • Find a common denominator (4).
  • Convert 12 to 24.
  • Add: 24 + 14 = 34

Using the calculator: Input Numerator 1 = 1, Denominator 1 = 2, Operation = +, Numerator 2 = 1, Denominator 2 = 4. The result will be 34.

2. Subtracting Fractions

Similar to addition, fractions must have a common denominator for subtraction. Once they do, subtract the numerators and keep the common denominator. Simplify if possible.

Formula: abcd = (a × d) – (c × b)(b × d)

Example: 3412

  • Common denominator is 4.
  • Convert 12 to 24.
  • Subtract: 3424 = 14

Using the calculator: Input Numerator 1 = 3, Denominator 1 = 4, Operation = -, Numerator 2 = 1, Denominator 2 = 2. The result will be 14.

3. Multiplying Fractions

Multiplying fractions is straightforward: multiply the numerators together and multiply the denominators together. Then, simplify the resulting fraction.

Formula: ab × cd = (a × c)(b × d)

Example: 23 × 14

  • Multiply numerators: 2 × 1 = 2
  • Multiply denominators: 3 × 4 = 12
  • Result: 212, which simplifies to 16

Using the calculator: Input Numerator 1 = 2, Denominator 1 = 3, Operation = *, Numerator 2 = 1, Denominator 2 = 4. The result will be 16.

4. Dividing Fractions

To divide fractions, you "flip" the second fraction (find its reciprocal) and then multiply it by the first fraction.

Formula: ab ÷ cd = ab × dc = (a × d)(b × c)

Example: 35 ÷ 12

  • Flip 12 to get 21.
  • Multiply: 35 × 21 = 65

Using the calculator: Input Numerator 1 = 3, Denominator 1 = 5, Operation = /, Numerator 2 = 1, Denominator 2 = 2. The result will be 65.

Simplifying Fractions

After performing any operation, it's good practice to simplify the resulting fraction to its lowest terms. This means dividing both the numerator and the denominator by their greatest common divisor (GCD). For instance, 24 simplifies to 12 because the GCD of 2 and 4 is 2.

Our Fraction Calculator automatically simplifies the result for you, making it easy to get the most concise answer. Just input your fractions and select the desired operation!

Leave a Reply

Your email address will not be published. Required fields are marked *