integer ratio
The exact fraction hiding inside every float
- numerator
- denominator
Every float is secretly a fraction. integer ratio (Basic data handling: FloatAsIntegerRatio) is the node that tells you which one: it takes a FLOAT and returns the exact pair of integers whose ratio equals it. One input, float_value, and two outputs - numerator and denominator, both INT.
0.5 → 1 / 2. 0.75 → 3 / 4. 0.25 → 1 / 4. If you're computing aspect ratios, crop sizes, or any "this is X of that" relationship, this is the cleanest way to get the reduced fraction out of a float that the language offers.
The gotcha that makes this interesting
Here's where people get tripped up, and it's worth understanding before you use it: floats don't store 0.75. They store the nearest binary fraction to it. So while 0.75 gives you the tidy 3/4 you expect, 0.1 gives you:
numerator = 3602879701896397
denominator = 36028797018963968
That's the exact value of the float that Python calls 0.1, and it is not the decimal ratio you learned in school. The node is being completely honest - that's what float.as_integer_ratio() returns - but if you're feeding it values like 0.1, 0.3, or anything a human would write as a clean decimal, you'll get big ugly integers out, not 1/10.
So this node shines with floats that are exactly representable - halves, quarters, eighths, and friends: 0.5, 0.25, 1.5, 0.125. Those come out beautifully reduced. It's also great for turning any float into an exact rational when you genuinely need the true value. Just don't expect it to "simplify" decimal-looking numbers.
When to reach for it
Aspect ratios are the natural home. Compute a width/height ratio, run it through this node, and you can read the fraction off the outputs - or feed numerator and denominator elsewhere as integers. It's also a nice exactness tool: if you want a float's true value without decimal formatting lying to you, this is the raw truth.
Installing it
Part of the Basic data handling pack by StableLlama. ComfyUI Manager → search "Basic data handling" → install → restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
then restart. No dependencies, no requirements.txt, no model files.
Troubleshooting
If your output integers look absurd (3602879701896397, say), that's not a bug - that's float precision doing its thing. Feed it 0.25 instead of 0.1 and you'll get the tidy 1/4. And remember: this node does not reduce the fraction of a decimal like 0.5 if the input wasn't exactly representable; stick to binary-friendly values for clean results.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| float_value | FLOAT | 0.00 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| numerator | INT | — |
| denominator | INT | — |