Decimal-to-Fraction Converter (DFC)

Last modified on


As opposed to KFC, this is DFC.

We can simply type or paste the number on the first input ➡️ hit Enter ➡️ bam!

The next input is for our own maximum denominator value, default is 1,000. The range for this input is 1 to 1e11 (1 × 10¹¹, one hundred billion) — it is used to converge a decimal to a rational approximation (i.e. to find the "best fraction" representation of a decimal number within the limit of a maximum denominator).

Remember to hit Enter button every time we change either input to trigger the conversion.

We can try 3.1416 or 3.14159, an approximation for π (pi) — credit to Master Liu Hui (3rd-century Chinese mathematician). The century is using Gregorian, not Confucian. Hence, 3rd. Chinese calendar runs in 60-year cycles, using a combination of the Ten Heavenly Stems (åĪĐåđē) and Twelve Earthly Branches (地æ”Ŋ). Take that, paper and pencil. But get this, Master Liu Hui lived in Three Kingdoms era.


About

DFC converts a decimal into a fraction by using the convergent method, which builds up increasingly accurate fractions through a stepping process. It stops once the denominator reaches 1,000 or our own limit (range: 1 - 1e11), ensuring the result stays simple and readable.

So, for example, with 1,000 as the maximum denominator, 0.333 becomes \( \frac{333}{1000} \) because that's already neat and within the limit — but 0.3333 gets converted to \( \frac{1}{3} \), since \( \frac{1}{3} \) is a better, cleaner fraction that still fits the allowed size.

This approach balances accuracy and simplicity.


DFC employs Number.EPSILON to do the floating-point comparison. Number.EPSILON = the smallest difference between 1 and the next larger representable floating-point number. In IEEE-754 double precision (which JS uses), that's about 2.220446049250313 × 10¯¹⁶.

Like this:

function nearlyEqual(a, b) {
  return Math.abs(a - b) < Number.EPSILON;
}

Because in JS, using === operator:

0.1 + 0.2 === 0.3 // is false.

But when use the Number.EPSILON:

nearlyEqual(0.1 + 0.2, 0.3) // is true.

Epsilon

Epsilon in Greek means, well, "epsilon". But in English, "a tiny thing" — because mathematicians can't resist nicking Greek letters.

In a pub conversation:

(Silent.)


Derailment

Once upon a time, KFC did mean Kentucky to Fried Chicken.

Precisely, with the to.

How long to get from Kentucky to Fried Chicken? ðŸĪ”

It's arbitrary. We could have plenty of scenarios. If the Fried Chicken is an actual place in Kentucky, well. Still, what part of Kentucky is the starting point?

Are you hungry now? 🍗ðŸĨĪ

— Credits to those bravely blissful hens who gave their thighs to fill our thighs in glory.

It's like that song from Michelle Branch — "Are You Hungry Now?" — that? You did listen to that, did you not? It sounded so melancholically angry.

Are you hungry now? ðŸ˜ĪðŸ’Ē💃 (Crumbling building and such.)

Indeed, Michelle didn't dance in the music video. The mellancholy was the combination of the jive of the music and lyrics, plus her stare. And perhaps her hidden fiery fists. — Could you look me in the eye? — indeed.

We can try to relisten to Michelle's 2000s exquisiteness, and swap the "happy" to "hungry".

Michelle Branch - Breathe ⬅️ Instead of "breathe", I sometimes heard "bleed". Mm.

Captivating guitar rhythm and atmosphere though — I was sudden-hooked by the intro riff. But at around 2:00 timestamp in the music video, we should see the bassist's surprised-dubstep.


Use DFC as Your Reference

Simply copy the URL from the address bar after you've done converting or typing your number.


This blue lad is one of the background stunts in that "accusatory-confirmative rhetorical question with pragmatic force behind it" song. — Are you hungry now? — Uh, I was. But, you're looking at me as if you were being constipated and sitting on posterior-boils with clenched fists.


Cheers!


This is a related post on Monkey Raptor on how to do it using pencil and paper.