Nodes/ComfyUI-JDCN/LogicUtil_Convert to Int
ComfyUI Node

LogicUtil_Convert to Int

Force any value into an integer, and know exactly what it'll do

By daxcay·Created 2 years ago·Updated about a year ago· 159
LogicUtil_Convert to Int
  • input1
  • INT

A good chunk of ComfyUI's widgets are integer-only - steps, seeds, batch sizes, indexes - and the graph keeps producing floats and strings. LogicUtil_Convert to Int takes input1 of any type and returns a INT. The catch is how it converts, because Python's int() has opinions, and knowing them saves you a head-scratch:

  • Floats are truncated, not rounded. int(3.9) → 3, int(-2.7) → -2. It drops the decimal, always toward zero. If you wanted rounding, use Round, Floor, or Ceil instead - this pack has all three.
  • Numeric strings parse: int("42") → 42. A string like "42.5" raises a ValueError - int() on a string won't parse decimals.
  • Booleans convert: int(True) → 1, int(False) → 0.
  • Everything else fails loudly with a traceback in the console.

The input defaults to 0, so an unwired node gives you 0 rather than erroring.

Where it fits

The canonical use is cleaning up a float before it hits an INT-only widget - a computed step count, a frame index, a seed derived from a calculation. It's also the fix when a text node hands you "128" as a string and you need it to be a number. And because the output type is guaranteed, it stops type-mismatch wiring errors before they happen.

It's one of the four Convert nodes in the pack's LogicUtil set (the LogicUtil_ prefix marks it as a port of the aria1th LogicUtils nodes), alongside Convert to Float, Convert to Bool, and Convert Combo to String.

Install

Ships in ComfyUI-JDCN. ComfyUI Manager → Install Custom Nodes → search "JDCN", or:

cd ComfyUI/custom_nodes
git clone https://github.com/daxcay/ComfyUI-JDCN.git
pip install -r requirements.txt

Only pack dependency is piexif (plus psutil, already in ComfyUI). Nothing to download.

Gotchas

  • Truncation is not rounding. This is the one that bites. int(2.9) is 2. If your float was the result of a division and you need the mathematically correct count, floor/ceil the division instead of converting.
  • "42.5" as a string crashes - numeric strings with decimals are a ValueError, not a silent truncation. Parse the float first, then convert, if you're dealing with decimal strings.
  • No visible feedback - like the other Convert nodes it doesn't print its output; wire it into a display node to see what actually came out.

Simple node, specific behavior. Read the bullet list once, and it'll never surprise you again.

CategoryLogicUtil

Inputs (1)

NameTypeDefaultDescription
input1*0

Outputs (1)

NameTypeDescription
INTINT