Fraction calculator

Simplify a fraction or add, subtract, multiply and divide two fractions.

Changing modes clears your inputs and result.

Integers only, with a nonzero denominator. The result is an exact reduced fraction with a positive denominator, without decimal rounding. Example: 12/18 = 2/3; zero becomes 0/1.

Your inputs stay in your browser. Displayed fractions are exact, without rounding.

Method and assumptions

Method version 1.0.0 · Updated

Simplify

Formula: (n ÷ GCD) / (d ÷ GCD)

Integers only, with a nonzero denominator. The result is an exact reduced fraction with a positive denominator, without decimal rounding. Example: 12/18 = 2/3; zero becomes 0/1.

numerator
Numerator
denominator
Denominator
Operations

Formula: a/b ± c/d = (ad ± bc)/bd ; (a/b) × (c/d) = ac/bd ; (a/b) ÷ (c/d) = ad/bc

Each integer is limited to ±9,007,199,254,740,991. Denominators and the divisor fraction must be nonzero. Exact calculation and final reduction, even when products exceed that limit. Example: 1/2 + 1/3 = 5/6.

numerator
Numerator
denominator
Denominator
operation
Operation
otherNumerator
Second numerator
otherDenominator
Second denominator

Integers within the stated limits; exact fraction without rounding. Fields accept neither decimals nor thousands separators.

Calculate with code

These short examples use the same inputs and core calculation as this tool. Adapt validation and formatting to your application.

JavaScript
function gcd(a, b) { return b === 0 ? Math.abs(a) : gcd(b, a % b); }
const n = 12, d = 18, divisor = gcd(n, d);
console.log(`${n / divisor}/${d / divisor}`); // 2/3
TypeScript
function gcd(a: number, b: number): number { return b === 0 ? Math.abs(a) : gcd(b, a % b); }
const divisor = gcd(12, 18);
console.log(`${12 / divisor}/${18 / divisor}`); // 2/3
Python
from math import gcd
n, d = 12, 18
g = gcd(n, d)
print(f"{n // g}/{d // g}")  # 2/3
Java
int n = 12, d = 18;
int g = java.math.BigInteger.valueOf(n).gcd(java.math.BigInteger.valueOf(d)).intValue();
System.out.println((n / g) + "/" + (d / g)); // 2/3
C#
int n = 12, d = 18;
int g = (int)System.Numerics.BigInteger.GreatestCommonDivisor(n, d);
Console.WriteLine($"{n / g}/{d / g}"); // 2/3