String to Int
Parse a Number Out of a Text Box Without the Whole Graph Exploding
- int
ComfyUI is picky about types. Feed a string into an integer input and the graph either errors or silently coerces something wrong. String to Int is the pack's answer: give it a text string and a fallback default, and it hands you a clean integer. If the string parses, you get the number; if it doesn't, you get the default instead of a crash. That "instead of a crash" is the entire selling point.
It exists for one main workflow: typing settings into a text field at runtime and converting them downstream. The filter nodes give you three extra text boxes precisely so you can type "20" for steps or "4" for a seed offset and let this node turn it into a real integer. Combined with Split String on character and its float sibling, a single 0.4, 20 string becomes denoise and steps for a sampler.
How it works
Two inputs, one output, no surprises:
string- the text to parse. Whitespace is stripped first, so " 20 " and "20" both work.default- what comes out if the parse fails. This is your safety net; pick something the graph can survive, because a bad string lands here, not on the floor.
The output int is the parsed value or the default. "20" → 20. "banana" → whatever you put in default. Empty string? Also the default.
Installing it
It's part of chrisgoringe/cg-image-filter - same install as the rest of the pack. ComfyUI Manager, search "cg-image-filter" or "Image Filter":
cd ComfyUI/custom_nodes
git clone https://github.com/chrisgoringe/cg-image-filter
Restart ComfyUI. No dependencies or models.
Gotchas
There's one real trap, and the README leads with it. This node was renamed (the class is cg_String to Int) because "String to Int" collided with identically-named nodes in other popular packs. If you load an old workflow after updating and get an error that the node doesn't exist, that's the cause - delete it and add it back fresh. Same advice applies across the pack: when a filter node acts up after an update, remove it and re-add it before hunting for a bug. And remember default is your friend: it's the difference between "tweak a string and keep generating" and "go hunting through a log for a parse error."
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| string | STRING | — | |
| default | INT | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| int | INT | — |