Nodes/noEmbryo nodes/String to Int /noEmbryo
ComfyUI Node

String to Int /noEmbryo

String to Int

By noembryo·Created 3 years ago·Updated 13 days ago· 47
String to Int /noEmbryo
    • INT
    ◄string►
    ◄default0►

    Some node hands you a number. It hands it to you as text. Everything downstream wants an INT, and a STRING output will not connect to an INT input - not with a warning, not with an implicit cast, it simply won't link.

    That's the whole reason StringToInt -noEmbryo exists. It's a two-line adapter between the string side of your graph and the numeric side.

    The mechanism, which is deliberately unglamorous

    The source is about as short as a node can be: it runs int(string.strip()) inside a try, and on any exception it returns the default value instead. That's it. Not a parser, not a coercer, not a validator - a conversion with a fallback.

    The fact that the failure path is a fallback rather than an error is the single most important thing to understand about this node, and it's the source of its one real footgun. More on that in a moment.

    The two inputs

    string is required, and it's declared with forceInput in the source - which means it renders as a socket you wire into, not a text box you type in. That's intentional: the node exists to convert a string that arrived from somewhere, so feeding it a literal number you'd have typed yourself is not the use case. If you want to type 1024 and hand it to an INT input, use an integer primitive - that's a different, simpler node.

    default is the other input: an INT widget, defaulting to 0, with the tooltip "used if the string can't be parsed as an integer." Treat it as your safety net and set it to a value you'd notice rather than something plausible. Left at 0, a typo silently turns your steps into 0 or your seed into a constant.

    The output is a single INT.

    What parses, and what quietly doesn't

    Because the parser is Python's int(), the rules are worth knowing exactly, since every failure is silent:

    • "1024", " 1024 ", "+12", "-7" → all fine. Whitespace is stripped, signs work.
    • "1024.0", "3.5", "1.5e3" → fail. There is no float handling here, so a decimal point kicks you straight to default. This catches people whose upstream string came out of a calculation.
    • "1,024" → fails. Thousand separators are not a thing int() knows about.
    • "0x10" → fails. Base 10 only.
    • "1_000" → 1000, no error. Python allows underscores in numeric literals, and this node inherits that parser wholesale rather than defining its own rules. Nobody expects this one.

    Newlines are fine - strip() clears them.

    Where it earns a place on the canvas

    The plumbing layer exists to fight repetition: one value, one authoritative source, fanned out to everything that needs it. This node is what lets a number live in a text source. Seed, steps, batch size, width, height - convert each widget to an input, drop this node in front of the ones fed by text, and the number is edited in one place instead of five.

    The other real use is numbers that arrive inside strings from elsewhere: an API or external node returning a count as text, a value parsed out of a filename, something a sibling utility node produced. There's no literal to type in those cases - the value comes from the graph, and a converter is the only tool that fits.

    Installing it

    Manager search noEmbryoNodes, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/noembryo/ComfyUI-noEmbryo
    

    Restart ComfyUI, then find it under Add Node > noEmbryo > Utils. As with the rest of this pack there's nothing to install beyond the clone - the project's pyproject.toml lists dependencies = [] and there are no model files.

    When it misbehaves

    • The value is 0 and it shouldn't be. That's the fallback firing. Your string didn't parse - most often because it contained a decimal point or a thousands separator. This is the node's one genuine trap: it never tells you it failed.
    • It refuses to queue. An unconnected required socket stops the run before it starts. You have to actually wire a STRING in; you can't leave it empty and hope.
    • You wanted 3.5 and got default. Correct behavior, wrong node. You need something that parses floats.

    Narrow, predictable, and about as risky as a node can be while still having a failure mode. If your workflow has a number trapped in a string, this is the two-second fix.

    CategorynoEmbryo/Utils

    Inputs (2)

    NameTypeDefaultDescription
    stringSTRINGwhitespace will be stripped before parsing
    defaultINT0used if the string can't be parsed as an integer

    Outputs (1)

    NameTypeDescription
    INTINT—