๐ผ> Float to Int
Round, floor, or ceil, when a downstream node insists on a whole number
- int
A tiny math-glue node: it takes a FLOAT and outputs an INT, using whichever rounding rule you pick. That's the whole thing, and it exists because ComfyUI is fairly strict about types on node sockets - a lot of nodes want an INT (a width, a step count, an index) but plenty of upstream math (a scale_ratio output, a percentage calculation, anything involving division) naturally produces a FLOAT, and you can't just wire one into the other.
Typical spot to use this: Scale Image to Side outputs a scale_ratio as a FLOAT; if you're using that ratio to compute something like a new step count or a coordinate elsewhere in the graph and the target socket wants an INT, Float to Int is the bridge.
How it works
It applies one of three standard rounding functions to the input float and outputs the result as an integer. Nothing more sophisticated than that - no scaling, no clamping, just the conversion.
The inputs and outputs that matter
float- the value to convert.function-round(nearest whole number, standard rounding),floor(always rounds down, toward negative infinity), orceil(always rounds up, toward positive infinity).
One output: int - wire it into whichever INT-only socket needed the conversion.
How to install it
Via ComfyUI Manager: search "yanc" or "YANC - Yet Another Node Collection," install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/ALatentPlace/ComfyUI_yanc
then restart. No dependencies, no downloads - it's a one-line math operation wrapped in a node.
Common issues & troubleshooting
Off-by-one results from the wrong rounding function. floor and ceil behave differently at exact half-values and around negative numbers than most people expect if they're not paying attention: floor always rounds down even for negative floats (so -1.2 becomes -2, not -1), and ceil always rounds up. If your downstream count is consistently one off, double-check which function you picked against what you actually wanted.
You didn't need this node at all. A handful of ComfyUI's built-in widgets auto-convert a float-producing connection to an int-expecting socket without complaint, depending on the node pair. Try the direct connection first - if ComfyUI accepts the link without an error, you don't need Float to Int in the middle; add it only when you hit an actual type-mismatch error on the wire.
Small floating-point noise causing unexpected rounding. If the float feeding this node comes from a chain of divisions/multiplications, tiny floating-point imprecision (2.9999999 instead of a clean 3.0) can push floor or ceil to a result one off from what you'd expect by hand. round is more forgiving of this than floor/ceil for values that are meant to land on a whole number.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| float | FLOAT | โ | |
| function | COMBO | 3 options: round, floor, ceil |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| int | INT | โ |