ComfyUI Node

to INT

Make it a whole number — but know it truncates, it doesn't round

By StableLlama·Created about a year ago·Updated 4 days ago· 48
to INT
  • input
  • INT

Seeds. Step counts. Batch sizes. If you've ever watched ComfyUI reject a float where an integer belongs, you know exactly why to INT exists. It converts any numeric input into an INT - and the important thing to know before you use it is that it truncates, it doesn't round. That distinction is the whole article.

It's part of Basic data handling, StableLlama's zero-dependency pack. Casting nodes are the quiet plumbing of any workflow that mixes types, and this one is among the most-used because so many core ComfyUI inputs demand integers.

How it works

The conversion is Python's int(input):

  • FLOAT → INT truncates toward zero. 2.9 becomes 2, -2.9 becomes -2. It throws away the fractional part - it does not round to the nearest integer.
  • numeric strings - "42", "-7" parse fine.
  • True1, False0.
  • Non-numeric input raises a ValueError.

There's one string gotcha that catches people: int() won't parse a float-string. int("42") works, but int("42.5") raises an error. If a string like "3.5" comes your way, you need to cast to FLOAT first (the pack's to FLOAT), then to INT.

The input and the output

  • input (ANY) - the number or numeric string to convert.
  • INT (output) - the converted value, fractional part dropped.

Installing it

Install Basic data handling from ComfyUI Manager (search "Basic data handling"), or:

cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling

Restart ComfyUI. No dependencies, no models.

Troubleshooting

  • "2.9 became 2 and I wanted 3." You want rounding, not truncation. Run the value through the pack's round node (set decimal_places to 0) and then cast to INT - or round to an int and let it flow. Casting alone will always chop, never round.
  • "It fails on '42.5'." As above - int() refuses float-strings. Go float-first, or fix the string upstream. This one confuses people every time it appears.
  • "I'm casting a seed and it changes my image." Casting a float seed to INT truncates it, which changes the seed's value. If you care about reproducibility, keep seeds as INTs from the start instead of casting a float back into one.
CategoryBasic/cast

Inputs (1)

NameTypeDefaultDescription
input*

Outputs (1)

NameTypeDescription
INTINT