To Int | Basic
Any value to a whole number, with your choice of rounding
- any
- INT
ToInt ("To Int | Basic") converts a value of any type into an integer, and the reason it's more useful than it sounds is the round_method dropdown. Take any input, choose how you want the fractional part handled, and get an INT out.
The input any is a wildcard that accepts anything. The optional round_method input has four choices, defaulting to round: round, floor, ceil, trunc. The node first converts whatever it receives to a float, then applies the chosen method - round to the nearest whole number, floor always down, ceil always up, trunc toward zero (so -2.7 becomes -2, not -3). If conversion fails entirely, you get 0 rather than an error. The output is INT.
The inputs that matter
- any - the value to convert.
- round_method - how to handle the decimal part. This is where the control is:
roundfor normal cases,floor/ceilwhen you need a value to never exceed or never undershoot a bound.
Why you'd reach for it
Same type-bridging job as ToFloat, but for whole numbers. Feed it a float when an INT socket refuses the wire, or convert a numeric string into something you can use as a seed or step count. The real value-add is the rounding choice: when you're deriving a size from a calculation and need it to round up (so an image never renders smaller than requested), ceil is exactly right - and this is one of the few places in a node graph where that choice is a dropdown instead of a math trick.
One honest note: round here is Python's banker's rounding, so 2.5 rounds to 2, not 3. For the vast majority of workflow values it doesn't matter, but if you're sitting exactly on a half-boundary, trunc or explicit ceil/floor will behave more predictably.
Installing it
Standard pack install - pure Python, zero dependencies:
cd ComfyUI/custom_nodes
git clone https://github.com/akatz-ai/ComfyUI-Basic-Math
Restart ComfyUI, find it under Basic Math ➕ → Conversion as "To Int | Basic". Or use ComfyUI Manager → **Install Custom Nodes → search "ComfyUI-Basic-Math"`.
The gotchas
The silent 0 on failed conversion is the behavior to remember - a non-numeric string quietly becomes zero instead of erroring. And because conversion goes through float first, extremely large integers can lose a little precision on the way; for the ranges ComfyUI actually uses it's a non-issue. Also, if you need decimals preserved rather than discarded, this is the wrong node - that's ToFloat. And the menu name carries the pack's usual | Basic suffix.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| any | * | — | |
| round_methodopt | COMBO | round | 4 options: round, floor, ceil, trunc |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| INT | INT | — |