ForHosting KIT · Math

Ratio of 2 numbers calculator

Compare two numbers as a ratio in lowest terms and as a decimal: 8 to 12 reduces to 2:3, with a greatest common divisor of 4 and a quotient of 0.666666666667. Decimals work too, so 1.5 to 2.5 becomes 3:5. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
A
8
B
12
You get
Quotient
0.6666666667
Gcd
4
Ratio a
2
Ratio b
3

A ratio of two numbers compares the first value to the second by dividing a by b and, when the pair shares a common factor, by reducing both terms to lowest terms. This calculator accepts two finite numbers named a and b, rejects a zero second number because division by zero is undefined, returns the decimal quotient a over b, and optionally simplifies the pair by dividing both integerized terms by their greatest common divisor.

What the ratio of two numbers is and how GCD simplification works

A ratio of two numbers is a comparison that asks how many times the first quantity contains the second, written either as a single quotient a divided by b or as the pair a colon b. Both forms describe the same relationship: eight to twelve is the same comparison as two to three once you cancel the common factor four, and it is also the same as the repeating decimal two thirds. The identity used here is elementary.

First compute the quotient a over b, which is defined only when b is not zero. Then, when simplification is requested, scale any decimals up to integers by a shared power of ten so that one point five to two point five becomes fifteen to twenty-five, apply the Euclidean algorithm to obtain the greatest common divisor of those integers, and divide both terms by that divisor.

The second term of the reduced pair is kept non-negative by flipping both signs when needed, the same convention used for a reduced fraction whose denominator is positive: eight to negative twelve becomes negative two to three, matching the negative quotient. Integers that are already coprime, such as seven to three, stay seven to three with a reported GCD of one. A zero first term and a non-zero second term reduce to zero to one.

This landing is not a fraction-arithmetic engine and does not add, subtract, or multiply fractions; it answers the search for a ratio of two numbers, which is the divide-and-optionally-reduce question students, mixers, and data pipelines actually type.

Where a two-number ratio earns its keep, and what this tool is not

Use this ratio of two numbers calculator when you have a pair of peer quantities and you want the reduced a colon b form together with the decimal quotient. Recipe scaling, map legends, gear teeth that you only want as a comparison and not as a mechanical gear train, classroom worksheets that ask to express 8:12 in simplest form, and data-cleaning scripts that store a mix ratio next to a real-valued rate are the usual cases.

Keep both inputs in one consistent unit before you call: metres to metres is a ratio, metres to kilometres is a unit conversion. If you instead have present and future ages, you want an age-ratio solver, which is a different search intent and a different formula. If you need to add or multiply two fractions, use a fraction calculator.

If you need a symmetric percent of the average, use percentage difference. Pin the rounded quotient and the ratio string in tests. This page targets people searching for a ratio of two numbers, simplify a ratio by GCD, or divide the first number by the second; it is not a percentage tool and not an age puzzle.

Classroom simplest-form checks

Let students submit two integers and verify the reduced a:b string and the GCD against a deterministic oracle, including the zero-denominator rejection.

Recipe and mix scaling

Reduce a measured pair such as 150 millilitres to 250 millilitres to 3:5, then scale the batch while keeping the same mix ratio.

Can I turn simplification off?

Yes. Set simplify to false to keep a:b as entered. The response still reports the GCD so you can reduce the pair later.

Do decimal inputs work?

Yes. Decimals are scaled to integers by a shared power of ten before the GCD step, so 1.5 and 2.5 simplify to 3:5.

What happens if the second number of the ratio is zero?

There is no result, because dividing by zero is undefined. The first number may be zero, though: zero compared with any non-zero number reduces to 0:1.

How are negative numbers handled in a ratio?

The second term is kept positive by flipping both signs when needed, just as with a fraction whose denominator is positive. So 8 to −12 becomes −2:3, which matches the negative quotient.

Do both numbers of a ratio need the same unit?

Yes. Convert them to one unit first, metres to metres for example, because a ratio compares like with like. Mixing units gives a pair that looks tidy but describes the wrong comparison.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/math/ratio-of-2-numbers

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/math/ratio-of-2-numbers \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"a":8,"b":12}'
{
  "a": 8,
  "b": 12
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "math.ratio_of_2_numbers",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_abs1000000000000000
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

The JSON echoes the inputs, reports the GCD, returns the reduced terms as a colon-separated ratio such as 2:3, and includes the quotient so you can use either the school-book a:b form or a single real number. Invalid input is not billed; a successful API call costs $0.002.

Input contract, response shape, and when the second number is zero

When simplify is true those terms are the reduced pair; when simplify is false they are the original a and b and the GCD is still included so you can reduce later. A formula string restates the identity for display next to the answer. Send a JSON body with two required finite numbers named a and b. Each field may arrive as a JSON number or as a numeric string that matches ordinary decimal or scientific notation; the aliases first and second are accepted for a and b. An optional boolean simplify defaults to true. Missing fields, empty strings, not-a-number values, and infinities fail with invalid_input and name the offending field. Absolute magnitudes above one quadrillion are rejected so products stay finite in IEEE double precision on the Worker and in the browser. A successful API request is charged the published $0.002 base price with unit item.

Where a two-number ratio earns its keep, and what this tool is not

Pair classroom examples deliberately: eight and twelve produce two to three with GCD four; one point five and two point five produce three to five; eight and zero demonstrates the invalid_input path. Failed tasks that return invalid_input do not consume prepaid balance. API pricing remains the flat $0.002 per successful request.

Data pipelines that store both forms

Keep the decimal quotient for arithmetic and the colon-separated reduced ratio for display, from the same isomorphic function in the browser and the API.

How is the ratio of two numbers calculated?

Send finite numbers a and b. The API returns the quotient a/b and, when simplify is true, the pair a:b reduced by the GCD of the integerized terms.

What happens if the second number is zero?

The task fails with invalid_input. A ratio is undefined when the second number is zero because that would be division by zero, and the request is not billed.

What does the ratio of two numbers calculator cost?

The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.

Read the full KIT documentation →