CalculatorSignAll calculators

Closest Fraction for a Decimal with a Denominator Limit Calculator

Search for the closest fraction to a finite decimal subject to a maximum denominator and display the signed difference.

Closest Fraction for a Decimal with a Denominator Limit Calculator

Result
—

Use this calculator on your site

Paste the full code, including the CalculatorSign credit, into a Custom HTML block on your site.

Preview widget

A finite decimal has an exact fraction, but that fraction may have a larger denominator than you want to use. This calculator searches for the closest fraction whose denominator is at or below a limit you set. It displays the chosen numerator and denominator, the fraction in decimal form, and the signed error. Use it when a worksheet asks for a small denominator or when you want to see the numerical cost of simplifying a measured decimal.

Decide whether you need exactness or a smaller denominator

An input like 0.318 is exactly 318 thousandths. Reduce 318/1000 by dividing both numbers by two, and you have 159/500. This is exact. If the largest allowed denominator is 20, an exact representation is impossible because 500 is already the smallest denominator of any equivalent fraction. The question then becomes which allowed fraction comes closest to the decimal you started with.

The maximum denominator is a ceiling on the number beneath the fraction bar. The calculation allows every positive denominator from one to that ceiling. It can return a smaller denominator when that gives a closer value. Type a plain decimal with up to nine digits on each side of the decimal point. A minus sign is accepted. Use a zero before the point for magnitudes below one, and enter the maximum denominator as a positive whole number.

Worked approximation for 0.318

With 20 as the ceiling, one candidate is 6/19. Divide six by nineteen to get approximately 0.3157894737. Subtract the target of 0.318 and the difference is approximately negative 0.0022105263. Another candidate, 1/3, is approximately 0.33333333. Its difference is positive 0.01533333, which is larger in absolute value. The search compares all of the allowed denominators and finds that 6/19 has the smallest absolute difference for this input.

With 500 as the ceiling, 159/500 becomes available. Its signed error is zero. Allowing larger denominators cannot increase the smallest achievable error, since every candidate considered under the old ceiling is still available. The best fraction can stay the same if the newly available denominators provide no closer result. This is why changing the ceiling by one sometimes changes the result and sometimes makes no difference.

Find one best numerator for each denominator

Fix the denominator at an integer such as 19. Multiply the decimal by 19, giving 6.042 for the worked input. The closest integer numerator is six because it is closer to 6.042 than either five or seven. Once the best numerator at that denominator is found, compare its fraction against the best entry already found from smaller denominators. There is no need to test every possible numerator at every step because no other numerator on the same denominator can be closer.

The comparison uses integers derived from the decimal digits. This avoids letting a rounded decimal display decide whether two candidates are equally close. The search checks denominators from smallest to largest, keeping the smaller denominator when different denominators give the same error. If the two neighboring numerators are exactly equally close for a fixed denominator, the calculator chooses the one closer to zero. For example, with a ceiling of one, 2.5 is halfway between two and three. The output gives 2/1 using that tie convention.

Interpret the error in the right direction

The signed error is the numeric value of the chosen fraction minus the decimal you entered. A negative result is below the target on the number line, while a positive result is above. For a negative input, an approximation below it is more negative. The search decides solely on the magnitude of the difference, so the chosen fraction can fall on either side. That distinction matters if the quantity you are representing must meet a minimum or stay below a limit. In such a case, identify the required direction before deciding whether the selected fraction fits.

A denominator ceiling does not necessarily describe the fractions allowed on a physical ruler or a drawing. A scale with markings by sixteenths may represent halves, quarters, and eighths while offering no direct mark for nineteenths. This tool allows every denominator through the ceiling. If your allowed fractions have a particular fixed denominator, round the decimal multiplied by that denominator and check the resulting fraction separately. The nearest fraction under a ceiling is a broader mathematical problem.

Frequently asked questions

Why does the closest fraction have a denominator smaller than my cap?

The denominator field limits the search. It does not require the chosen fraction to use that exact denominator. A smaller denominator can give a closer value or the same exact value.

Can an input represent a number greater than one?

The result can be an improper fraction or a whole number over one. The numerator is chosen by the same nearest-value rule regardless of the size of the decimal input.

Is the displayed decimal the exact fraction value?

The fraction is the exact representation of the selected approximation. Its decimal display may be rounded when division continues indefinitely.

Will a denominator cap always introduce error?

A cap introduces error only when there is no equivalent fraction within the permitted denominator range. An exact reduced form that fits the ceiling has zero error.