String To Number
Turning Text Back Into Numbers ComfyUI Can Do Math On
- default_value
- result
ComfyUI is picky about types: a STRING socket will not plug into an INT or FLOAT socket, even when the text in question is "128" and you can see with your own eyes that it's a number. UC_StringToNumber is the little adapter that fixes exactly that. Feed it numeric text, get a number out.
Why you'd reach for it
Any time a number arrives wrapped in text, this is the node. The most common case is UC_GetJsonValue - pull a value out of a JSON blob and it comes back as a string, so a seed or dimension plucked from metadata needs converting before it'll drive a KSampler. The same goes for text files, CSV-ish inputs, or a wildcard system that hands you "512" as a string. One UC_StringToNumber and the value is usable as a real numeric socket.
It's the inverse of UC_NumberToString, and it complements the pack's UC_MathNumberConvert, which converts between number types without touching text.
How it works
The string input is parsed, and the node's decision is simple: if the text contains a . it's a float, otherwise an int. "3.14" → FLOAT 3.14, "42" → INT 42. What makes it friendlier than a raw int() in a script is the fallback: an optional default_value input (a match-type socket, so it'll take whatever numeric type you're working in) is returned when parsing fails. Leave it disconnected and the fallback is 0. So a genuinely unparseable string doesn't blow up your workflow - it quietly becomes the default you chose, which is usually the behavior you want in a pipeline.
The output is a match-type result socket, meaning it adapts to whatever numeric type you connect it to - plug it into an INT socket and it behaves as an integer, into a FLOAT socket and it behaves as a float. That's the same "wildcard-ish" trick all the pack's math nodes use to stay flexible.
Installing it
It's part of ComfyUI-UtilsCollection by silveroxides:
cd ComfyUI/custom_nodes
git clone https://github.com/silveroxides/ComfyUI-UtilsCollection
Restart ComfyUI, or search "ComfyUI-UtilsCollection" in Manager. The pack's requirements are opencv-python and typing-extensions; this node uses neither - it's pure Python.
Where people get burned
The float-vs-int guess. If your text is "1.0" it becomes a FLOAT even if you only care about the integer 1 - feed that into a strict INT socket and you may get a type error until you convert. And remember the fallback fires on any parse failure, including a leading $ or a trailing space that slipped in from a caption file. If you see values mysteriously snap to your default, that's the sign - clean the string upstream or check what your JSON actually returned.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| string | STRING | — | |
| default_valueopt | COMFY_MATCHTYPE_V3 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| result | COMFY_MATCHTYPE_V3 | — |