Nodes/ComfyUI-ZML-Image/ZML_整数字符串互转
ComfyUI Node

ZML_整数字符串互转

Turning numbers into text and back — with one footgun

By zml-w·Created about a year ago·Updated 2 months ago· 218
ZML_整数字符串互转
    • 字符串
    • 整数
    整数
    字符串

    ZML_IntegerStringConverter (ZML_整数字符串互转, "integer-string interconvert") is the node you reach for when a filename, a prompt tag, or a JSON payload needs a number as text - or when text needs to become a number and every other node is refusing. It's a one-purpose plumbing node from the big ComfyUI-ZML-Image pack, and like its converter siblings it's nearly invisible until the moment you need it, at which point it's exactly right.

    How it works

    Two optional inputs, two outputs:

    • 整数 (INT) in → 字符串 (STRING) out: str() of the number. 42 becomes "42". Feed it to a text-join node, a filename pattern, a prompt, whatever wants text.
    • 字符串 (STRING) in → 整数 (INT) out: int() of the text. "42" becomes 42.

    Both inputs are optional and it converts whichever side is connected; leave the other side empty and it outputs the default for that direction (empty string / zero).

    The footgun

    If the string can't be parsed as an integer - "42px", "3.5", "four" - the node silently returns 0 instead of erroring. No warning, no exception, just a 0 flowing into whatever's downstream. That's a deliberate "fail soft" choice, and it's the one way this node can cost you twenty minutes: you'll chase a weird 0 somewhere in a workflow and eventually trace it back to a string that contained a non-digit. If your text might be dirty, sanitize it first (or check the value with a comparison node before trusting it).

    A related subtlety: int() is strict. It won't parse "3.5" (that's a float, not an integer), and it will happily parse " 42 " with leading/trailing whitespace. So the failure mode is specifically non-numeric characters.

    When you'd use it

    • Filenames - turning a counter or seed integer into the text part of a save name.
    • Prompt assembly - injecting a step count or weight number into a text string that feeds a text-join or CLIP encode.
    • Reading config - pulling a number out of a text node or a JSON-ish string and handing it to a numeric control.

    It's pure plumbing, in the best sense: it exists to fight the type friction between the integer and string worlds of a graph.

    Installing it

    Pack install:

    cd ComfyUI/custom_nodes
    git clone https://github.com/zml-w/ComfyUI-ZML-Image
    

    restart ComfyUI, or ComfyUI Manager → search "ComfyUI-ZML-Image". Pure Python, no models, no dependencies beyond core.

    When you don't need it

    Core ComfyUI's PrimitiveString and the "convert widget to input" mechanic cover most casual cases. This node earns its slot once you're inside the ZML pack - its text and integer nodes are everywhere, and the converter is the bridge between them. Just remember the silent-zero behavior. Test the string you feed it, and don't let a stray character poison your pipeline.

    Categoryimage/ZML_图像/整数

    Inputs (2)

    NameTypeDefaultDescription
    整数optINT
    字符串optSTRING

    Outputs (2)

    NameTypeDescription
    字符串STRING
    整数INT