Nodes/ComfyUI-ZFRNodes/Convert To Integer
ComfyUI Node

Convert To Integer

Getting Whole Numbers Out of Strings, Floats, and Booleans

By zfrsgtcu·Created 3 months ago·Updated 13 days ago· 32
Convert To Integer
  • input
  • output

The loop-counter problem

Almost every automation workflow eventually needs a whole number and gets handed something that isn't one. Loop nodes want an INT for their iteration count; seeds, steps, and batch sizes are all integers. But the LLM you asked for "a batch of 5" answers with the text "5", and a JSON Extract node hands you 5.0 a surprising amount of the time. ComfyUI's typed graph will not let a STRING or FLOAT wire plug into an INT port, so you're stuck until something coerces it.

That something is Convert To Integer, one of the four nodes in the ComfyUI-TypeConverters pack. It takes a single ANY input and returns a hard INT. The README's canonical example is Ollama → Convert To Integer → For Loop, and that's the exact shape of problem it exists to solve.

How it works

The conversion tries the direct route first, then works its way down a fallback ladder until something sticks, ending at 0 if everything fails:

  • A number converts directly: 6 stays 6, True becomes 1, False becomes 0, and None becomes 0.
  • A float gets truncated, not rounded - 6.9 becomes 6. If you need 7, round before you convert.
  • Text gets parsed as a number: "6" becomes 6.
  • Strings that mean yes or no also count: "true", "yes", "y", "on"1; "false", "no", "n", "off"0.
  • Anything unparseable - "banana", an object, a tensor - falls back to 0.

That last point is worth internalizing: this node never throws. A bad value silently becomes zero, which is safe for a loop count but easy to miss if you were expecting a specific number.

The inputs and outputs that matter

  • input (ANY) - accepts anything, which is what lets it sit between mismatched types.
  • output (INT) - the whole number, ready for seed, step, batch, or loop-count ports.

Reach for it whenever an LLM or API returns a count, whenever a For Loop won't accept what's feeding it, or whenever you need to shove a number into something that demands a clean INT.

Installing it

ComfyUI Manager: search the pack title "ComfyUI-TypeConverters" and install. Manual route:

cd ComfyUI/custom_nodes
git clone https://github.com/zfrsgtcu/ComfyUI-TypeConverters

Restart and look under zfr-nodes. There are no model downloads and no dependencies to fight - the pack is one pure-Python file, MIT-licensed. If a red wire appears after a recent ComfyUI update, check that you actually restarted; these nodes are so small there's nothing else to break.

One trap to remember

The truncation is the thing that bites people. 6.96, not 7. If you're converting a float denoise value or a ratio into a step count, that off-by-one shows up in places you'd rather not discover it. And when a string says "5.5", the node does get you to 5 - so if the answer smells wrong, check whether the source really was an integer in the first place.

Categoryzfr-nodes

Inputs (1)

NameTypeDefaultDescription
input*

Outputs (1)

NameTypeDescription
outputINT