Decimal expansion of a fraction
1/3 comes back as 0.(3) and 1/7 as 0.(142857), with the repeating block in parentheses, while a fraction that ends, like 1/8, gives a clean 0.125. You always know whether a decimal is exact. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Numerator
- 1
- Denominator
- 8
- Value
- 0.125
- Decimal
- 0.125
You get the plain numeric value, an exact decimal string built by real long division, and, when the expansion repeats forever, the repeating block clearly marked, so 1/3 comes back as 0.(3) instead of a vague 0.3333333333333333. A zero denominator is rejected with a clear error, because division by zero is undefined. It runs entirely in deterministic arithmetic: no network, no randomness, no approximation beyond the final floating-point value.
Why a decimal expansion is more than a division
Anyone can type a division into a calculator and read a handful of digits off the screen. The problem is that a calculator silently decides how many digits to show, and what it hides is often the part that matters. One third is not 0.3333333333 — it is 0.3 repeating forever, and treating the truncated display as the true value introduces a rounding error that compounds across every later step of a computation.
The moment a remainder appears for the second time, the expansion is guaranteed to cycle from that point onward, and the repeating block is reported exactly, wrapped in parentheses. Terminating fractions such as 1/8 come back as a clean finite string with no padding and no spurious trailing digits, so you always know whether the decimal you hold is exact or an abbreviation of an infinite one.
How the algorithm works
Signs are handled separately so the magnitude can be divided with plain integer arithmetic. The integer part falls out of a single floor division; then the fractional part is produced digit by digit by the classic schoolbook loop — multiply the remainder by ten, take the next digit, keep the new remainder. A map from each remainder to the position where it first appeared detects a cycle in constant time, so a fraction like 1/7 returns 0.(142857) after a handful of steps instead of wandering on forever.
The expansion is hard-capped at two hundred fractional digits; if a cycle has not closed by then, the string is marked as truncated rather than pretending to be exact. The plain numeric value, computed once in floating point, is included alongside for callers who just need a number.
Where it fits in a pipeline
Fraction-to-decimal conversion shows up anywhere rational numbers travel between systems: school platforms that must display exact answers, pricing engines that store unit costs as fractions and need decimals for invoices, measurement tools converting imperial fractions to decimal inches, and test suites that verify a symbolic math library against a ground truth. In each case the danger is the same — an invisible rounding that survives into a document or a database. Nothing you send is stored: the fraction is converted and discarded, and only the expansion is returned.
What you can do with it
Display exact answers in education software
Show 1/7 as 0.(142857) with the repeating block marked, instead of a silently rounded 0.142857 that marks a correct student answer wrong.
Convert stored fractions for invoices and reports
Turn rational unit costs like 7/12 into their decimal form with full knowledge of where the expansion repeats, before formatting money.
Ground-truth a symbolic math library
Diff your library's decimal output against a deterministic long-division reference in a test suite, fraction by fraction.
FAQ
How are repeating decimals represented?
The repeating block is wrapped in parentheses in the decimal string — 1/3 becomes 0.(3) — and also returned on its own in the repeating field. Terminating fractions carry no repeating field at all.
Is there a limit on the expansion length?
Yes: the fractional part is capped at 200 digits. If no cycle closes before then, the string ends with an ellipsis and the result is flagged as truncated rather than presented as exact.
Is the input stored anywhere?
No. The numerator and denominator are processed in memory and discarded; only the decimal expansion is returned.
What happens if the denominator is zero?
The fraction is rejected with a clear message instead of a result, because division by zero has no defined value. Showing infinity or a long row of digits would only hide the mistake.
Why not just read the digits off a calculator?
A calculator decides on its own how many digits to show and hides the rest. One third is not 0.3333333333 but a 3 repeating forever, and treating the cut-off display as exact adds a rounding error that grows through every later step.
Related tools
For developers — API access
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.
API endpoint
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.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/math/decimal \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"numerator":1,"denominator":8}'const res = await fetch("https://api.kit.forhosting.com/math/decimal", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"numerator": 1,
"denominator": 8
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/decimal",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"numerator": 1,
"denominator": 8
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/decimal", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"numerator":1,"denominator":8}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"numerator":1,"denominator":8}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/decimal", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"numerator": 1,
"denominator": 8
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.decimal",
"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.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
The decimal expansion API takes a fraction — a numerator and a denominator — and returns what that fraction looks like as a decimal number. The same code that answers the API runs free in your browser on this page, so you can check a single fraction by hand and only pay when you automate the conversion of thousands.
Why a decimal expansion is more than a division
This endpoint performs the long division the way you would on paper, keeping every intermediate remainder, and it watches those remainders for a repeat.
How the algorithm works
The input is validated first: both fields must be finite numbers, and the denominator must not be zero, because division by zero has no defined result and the request is rejected with an invalid_input error rather than a misleading infinity.
Where it fits in a pipeline
Running the conversion through this endpoint gives you a deterministic, repeatable string you can diff, store and audit, plus an explicit flag when the true expansion repeats. It costs $0.002 per request through the API, with no per-unit surcharge, and it is also free to run in your browser on this page for one-off checks.
Technical questions
What does it cost?
$0.002 per request, with no per-unit surcharge. It is also free to run in your browser on this page.
What happens if the denominator is zero?
The request is rejected with an invalid_input error explaining that division by zero is undefined. Zero-denominator requests are not charged.
Can I send the numbers as strings?
Yes. Numeric strings such as "22" and "7" are accepted and coerced, but they must parse to finite numbers or the request is rejected.