Skip to content
🛠️ToolsShed

Fraction Calculator

Add, subtract, multiply, and divide fractions with step-by-step solutions.

Fraction 1
Operation
Fraction 2

About this tool

A fraction calculator simplifies the process of performing arithmetic operations on fractions—addition, subtraction, multiplication, and division. Whether you're a student learning basic math concepts, helping with homework, or an adult refreshing your understanding of fractions, this tool provides instant, accurate results without the need for manual calculations or complex formulas.

To use the fraction calculator, simply enter the numerator and denominator for each fraction in the input fields, select the operation you want to perform (add, subtract, multiply, or divide), and click the Calculate button. The tool displays not only the final answer in simplified form, but also breaks down the step-by-step process so you can understand exactly how the operation was completed and learn the method behind the calculation.

Frequently Asked Questions

Code Implementation

from fractions import Fraction
import math

# Python's built-in Fraction class handles exact rational arithmetic
a = Fraction(1, 3)    # 1/3
b = Fraction(1, 4)    # 1/4

print(a + b)   # 7/12
print(a - b)   # 1/12
print(a * b)   # 1/12
print(a / b)   # 4/3

# Auto-simplification
print(Fraction(8, 12))   # 2/3 (auto-simplified)
print(Fraction(6, 4))    # 3/2

# Mixed numbers
mixed = Fraction(2) + Fraction(3, 4)  # 2 + 3/4
print(mixed)   # 11/4
print(int(mixed), mixed - int(mixed))  # 2  3/4

# Manual implementation
def gcd(a, b):
    return math.gcd(abs(a), abs(b))

def lcm(a, b):
    return abs(a * b) // math.gcd(a, b)

def add_fractions(n1, d1, n2, d2):
    common = lcm(d1, d2)
    result_n = n1 * (common // d1) + n2 * (common // d2)
    g = gcd(result_n, common)
    return result_n // g, common // g

print(add_fractions(1, 3, 1, 4))  # (7, 12)

# Comparing fractions
f1 = Fraction(3, 7)
f2 = Fraction(2, 5)
print(f1 > f2)   # True (3/7 > 2/5 since 15 > 14)

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.