Float → Int
Truncation, not rounding — the trap that eats 2.999
- INT
This is the node you reach for the moment a sampler or a math chain hands you a float and the next node demands an integer. ComfyUI is strict about that direction - a FLOAT wire won't plug into an INT input - so somewhere between "computed a denoise value" and "this port wants whole numbers," you need a cast. SL_FloatToInt is that cast.
But read this twice: it truncates, it does not round. The code is int(value), which chops the decimal off toward zero. 3.9 → 3. 3.1 → 3. -3.9 → -3. There is no rounding in this pack anywhere. Most people get burned by the near-integer case: you compute something that should be 3, float precision leaves you with 2.999999, and this node hands you 2. If your workflow depends on the "right" whole number, round upstream with a math node before converting, or check your values with SL_CompareFloat first.
Where it shows up in real graphs:
- Width/height and batch sizes computed from an aspect ratio or a scaling factor - the "calculate, then cast to INT" pattern.
- Seeds and step counts that were produced by arithmetic rather than by a slider.
- Any FLOAT output feeding a core ComfyUI node that insists on INT - the classic red-link scenario.
Inputs and outputs are minimal:
value(FLOAT) - default 0.0. An INT wire also plugs in here fine, since floats accept ints.- Output:
INT- the truncated value.
Installing it
Ships with ComfyUI-SimpleLogics. In ComfyUI Manager, search "SimpleLogics" under Install Custom Nodes, install, restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/danipisca07/ComfyUI-SimpleLogics
Restart and find it via Add Node → search "Float → Int" (menu group SimpleLogics/Convert). No dependencies, no model files - the whole pack is stdlib-only Python, so there's nothing extra to download.
Gotchas worth remembering
- Truncation toward zero, not floor. For positive numbers it doesn't matter, but -1.7 becomes -1, not -2. If you expected Python's floor, that's a different thing.
- Precision noise is real. A float computed as
1/3 * 3might not be exactly 1.0; it can land at 0.9999999 and truncate to 0. When the answer looks "close," verify the actual value first. - Don't put it mid-chain. Convert to INT as late as possible so the graph keeps its decimal precision where it still needs it. Converting early then converting back is how you lose data for no reason.
It's one of the most genuinely useful nodes in the pack because the INT/FLOAT mismatch is so common. Just keep the truncation rule tattooed on your brain, and you'll be fine.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| value | FLOAT | 0.00 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| INT | INT | — |