ComfyUI Node

String to Integer

Parse a number out of a text string

By jamesWalker55·Created 3 years ago·Updated about a year ago· 215
String to Integer
    • INT
    text0

    Takes a text string like "42" and turns it into an actual integer you can do math with. Text and numbers are different types in ComfyUI, and a string that happens to contain digits isn't a number until something parses it - that's this node's job.

    Where it matters is when a value arrives as text and needs to become a number. You pulled a line out of a multiline prompt, read a value from a filename you split apart, or got a string from some node that only speaks text, and now you want to feed it into a resolution, a seed, a frame index, or any math node. This is the bridge from "characters that look like a number" to "a number the graph can compute with."

    How it works

    It parses the string as an integer - the equivalent of int("42") in Python. The digits become the numeric value.

    Inputs and outputs

    • text - the string to parse. Default is "0".

    Output is a single INT.

    Installing it

    Part of the pack's comfyui_primitive_ops file. Install via ComfyUI Manager (search Various ComfyUI Nodes by Type / comfyui-various) or clone:

    cd ComfyUI/custom_nodes
    git clone https://github.com/jamesWalker55/comfyui-various
    

    Restart ComfyUI. No models, no extra dependencies.

    Common issues

    The thing that trips people is that the string has to actually be a whole number. Parsing is strict:

    • Non-numeric text errors out. "abc", or "512px", or an empty string - none of those parse to an integer, and the node will throw rather than guess. If your text might have junk around the number, clean it first (the pack's JWStringReplace can strip characters, or JWStringSplit can isolate the numeric part).
    • Decimals aren't integers. "3.5" won't parse as an int either. If your string holds a decimal, use JWStringToFloat instead, then convert to int if you need to.
    • Stray whitespace from a split or a copied line can sometimes cause trouble, so trim if you're getting unexpected errors.

    The fix is almost always upstream: make sure whatever produces the text hands over clean digits and nothing else. A common real chain is JWStringGetLineJWStringToInteger: pull a line of text that holds a number, then parse it. If that line has a stray label, a unit, or trailing whitespace, the parse fails - so slot a JWStringReplace in between to strip the junk, and only then convert. Once the text is clean digits, this node is completely reliable.

    If it loads red as a missing node in a downloaded workflow - these JW utilities show up in shared graphs all the time - the pack isn't installed. Run Manager's "Install Missing Custom Nodes" or clone the repo above.

    CategoryjamesWalker55

    Inputs (1)

    NameTypeDefaultDescription
    textSTRING0

    Outputs (1)

    NameTypeDescription
    INTINT