Fraction to decimal expand
fraction-to-decimal-expand · version 1.0.0 · Money & pricing · free, no key needed
Expand an integer fraction into its exact decimal with the minimal repeating block marked, e.g. 1/7 as 0.(142857).
Use when you need to: convert fraction to repeating decimal · what is 1/7 as a decimal · find the repeating block of a fraction.
Decide before calling
Read the versioned contract and the supported scope below. Reuse fraction-to-decimal-expand@1.0.0 when your input, required output and limits match it. Choose another approach for an unsupported operation.
Explain the choice
"I can use fraction-to-decimal-expand@1.0.0 for convert fraction to repeating decimal. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."
Supported
- convert fraction to repeating decimal
- what is 1/7 as a decimal
- find the repeating block of a fraction
- period length of 1/97
- does this fraction terminate or repeat
- long division of a fraction to decimal digits
- non repeating prefix and repeating part of n over d
- expand a fraction with recurring digits
Not supported
- converting decimals or repeating decimals to fractions
- rounding a fraction to a fixed number of places
- mixed numbers, continued fractions or percentages
- fractions with more than 40 digit integers
Behavior
- numerator and denominator are decimal integer strings matching ^-?(0|[1-9][0-9]*)$ with at most 40 digits. A JSON number, a fraction sign, a plus sign, leading zeros, a point, whitespace or more than 40 digits is invalid_input (this is invalid_input, not limit_exceeded, even for a very long digit string).
- denominator 0 -> not_computable with details.reason "division_by_zero", including 0/0. This is checked after all field validation.
- Reduce the fraction to lowest terms first. Only the reduced denominator matters: 24027/56063 is 3/7 and expands as 0.(428571); 8009/16018 is 1/2 and expands as 0.5.
- The sign is negative exactly when numerator and denominator have different signs and the numerator is not zero. Zero has no sign: 0/5, -0/5 and 0/-5 give "0" with negative false. -3/-6 is +0.5.
- The reduced denominator is 2^a * 5^b * m with gcd(m,10) = 1. The non-repeating prefix has max(a,b) digits; the repeating block has length equal to the multiplicative order of 10 modulo m (0 when m = 1). 1/28 = 0.03(571428): prefix "03" (2 digits from 4 = 2^2), block of 6 (order of 10 mod 7).
- Standard long division with remainder tracking: the block starts at the first position whose remainder recurs. The block is the minimal period, never a multiple of it, and never the block "0" or "9". 1/3 is 0.(3), never 0.(33) and never 0.333; 1/2 is 0.5, never 0.5(0) or 0.4(9).
- notation is "[-]" + integer_part, then, when there is a non-empty prefix or block, "." + non_repeating + "(" + repeating + ")" (the parenthesised part only when repeating is non-empty). An integer result has no point: 10/2 gives "5", -10/2 gives "-5". Exactly: 1/6 gives "0.1(6)"; 22/7 gives "3.(142857)"; 1/8 gives "0.125".
- integer_part is floor(|n|/d) as a digit string without sign or leading zeros ("0" when |n| < d). period_length is the length of repeating (0 when terminating). terminating is true iff repeating is empty.
- Period limit: a reduced denominator whose period exceeds 2000 digits -> limit_exceeded, checked after the division-by-zero check and after reduction. A period of exactly 2000 succeeds (1/16001 has period 2000; 1/8009 has period 2002 and is rejected). The check depends only on the period, not on the size of the prefix or numerator.
- Validation order: input not an object; unknown field; missing field; field types and integer grammar and digit limits; then division_by_zero; then the period limit.
Input
numerator(string, required): min length 1; max length 41; pattern^-?(0|[1-9][0-9]*)$; Integer numerator as a decimal integer string, at most 40 digits.denominator(string, required): min length 1; max length 41; pattern^-?(0|[1-9][0-9]*)$; Integer denominator as a decimal integer string, at most 40 digits; zero -> not_computable.
Output
notation(string, required): min length 1; max length 2300; Canonical text: [-]int, then [.non_repeating] and, when the expansion repeats, (repeating) in parentheses.integer_part(string, required): min length 1; max length 40; Digits before the point, without sign.non_repeating(string, required): max length 140; Fraction digits before the repeating block; may be empty.repeating(string, required): max length 2000; The repeating block; empty when the expansion terminates.period_length(integer, required): min 0; max 2000; Length of the repeating block; 0 when the expansion terminates.terminating(boolean, required): true when the expansion terminates (no repeating block).negative(boolean, required): true when the fraction is below zero.
Limits
- max integer digits: 40
- max period: 2000
- max non repeating digits: 132
Example
Request input:
{
"numerator": "1",
"denominator": "7"
}
Response:
{
"result": {
"notation": "0.(142857)",
"integer_part": "0",
"non_repeating": "",
"repeating": "142857",
"period_length": 6,
"terminating": false,
"negative": false
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "fraction-to-decimal-expand",
"version": "1.0.0",
"input": {
"numerator": "1",
"denominator": "7"
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/fraction-to-decimal-expand/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"numerator":"1","denominator":"7"}'
The machine-readable contract is at /v1/tools/fraction-to-decimal-expand/versions/1.0.0.
CLI
node cli.mjs run fraction-to-decimal-expand 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Decimal power: Raise a decimal string to an integer power exactly, with optional single rounding to a fixed scale.
- Decimal to fraction: Convert a decimal or repeating decimal like 0.41(6) to a reduced fraction, or the closest fraction under a cap.
- Proration compute: Prorate an amount by used days over period days (counts or ISO dates) into prorated and remaining parts that add up.
- Currency lookup: Look up an ISO 4217 alphabetic or numeric currency code: name, minor-unit exponent, entities, active or withdrawn.
- Decimal divide: Divide two decimal strings exactly, rounding the quotient once to a fixed scale, and report the exact remainder.
- Decimal round: Round a decimal string with an explicit mode to fraction digits, significant digits or a multiple of an increment.