ComfyUI Node

String → Int

'3.9' becomes 3, and that's by design

By danipisca07·Created 6 months ago·Updated 6 months ago· 0
String → Int
    • INT
    value0

    String → Int parses a string into an integer, and it has one quirk that catches everyone: it truncates, it doesn't round. Feed it "3.9" and you get 3, not 4. The author's description says this outright - "Accepts decimal strings like '3.9' (truncated to 3)" - so it's deliberate, but it's the kind of deliberate you'll rediscover the hard way if you skim past it.

    Why you'd reach for it

    You need an integer where a string currently lives. The usual suspects: a step count or batch size read out of a settings string, a seed recovered from a filename or metadata, an image dimension pulled from a text field. Everything text-based that needs to feed an INT socket - KSampler steps, width and height, batch size - has to go through a parse like this first.

    It's also the practical answer to the Number → String node's .0 problem. If your workflow stringified a number and now wants the integer back, String → Int cleanly drops the decimal instead of fighting it.

    How it works

    The implementation is int(float(value)) - it first parses the text as a float, then truncates. That two-step matters: it's why "3.9" works at all (a plain int("3.9") would crash), and it's why the result is truncation toward zero, not rounding. "3.9"3, "-2.7"-2. Whitespace and scientific notation are tolerated the same way float() tolerates them. But non-numeric text is a hard stop: "abc" or "3.5 steps" throws a Python ValueError, which shows up as a red node.

    The inputs that matter

    One required input:

    • value - the STRING to parse (defaults to "0")

    One INT output.

    Installing it

    Ships in danipisca07/ComfyUI-SimpleLogics, the dependency-free pure-Python pack - no requirements.txt, no models to download. Install from ComfyUI Manager (search "SimpleLogics") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/danipisca07/ComfyUI-SimpleLogics
    

    Restart ComfyUI and you're set.

    Common issues

    Two things to keep straight. First, truncation: if your workflow assumes rounding, a "3.9" turning into 3 will silently nudge results. If you genuinely need round-to-nearest, do the rounding upstream and then parse. Second, garbage text: any string that isn't a number makes the node throw. A string like "3,9" with a comma decimal is a classic off-by-thousand gotcha - it's not valid Python float syntax, so it errors. The red node is telling you the text isn't numeric, not that the node is broken. (And yes, same pack quirk as every node here: an undocumented GeoCalib camera node registers alongside these - ignore it.)

    CategorySimpleLogics/Convert

    Inputs (1)

    NameTypeDefaultDescription
    valueSTRING0

    Outputs (1)

    NameTypeDescription
    INTINT