Nodes/ymc-node-suite-comfyui/switch a and b (isRoundTo)
ComfyUI Node

switch a and b (isRoundTo)

A text switch that decides by rounding two strings

By YMC-GitHub·Created 3 years ago·Updated about a year ago· 20
switch a and b (isRoundTo)
    • text
    a
    b
    text1
    isRoundTo1

    The plain switch a and b needs a real BOOL to flip. Switch a and b (isRoundTo) is the version for the rest of your graph - the parts where your condition is a string. It takes two text choices plus a text value and an isRoundTo target, does a rounding comparison between the two strings, and returns a or b depending on the result. No BOOL socket required.

    This is the node that closes the loop on the suite's "numbers as strings" philosophy. If your seed, your batch index, or some extracted value is sitting in a text field, you can branch on it without casting: wire text from wherever the number lives, set isRoundTo to the threshold, and route two prompts. The (isRoundTo) suffix is the whole story - the decision is "does this string round to that string?"

    How it works

    It reuses the same comparison as the is round to x node: both text and isRoundTo go through int(round(float(value))) and are tested for equality. If they match, you get a; if not, b. So with text = "0.8" and isRoundTo = "1", the comparison is 1 == 1, and the node returns a. With text = "0.4", it returns b. The rounding gives you a threshold with a fuzz band, which is handy for values that come out slightly off a target.

    Inputs and outputs

    • a - STRING, returned when the comparison matches
    • b - STRING, returned when it doesn't
    • text - STRING, the value under test, default "1"
    • isRoundTo - STRING, the target, default "1"
    • Output: text - either a or b

    Installing it

    # ComfyUI Manager: search "ymc suite" and install ymc-node-suite-comfyui
    # or:
    cd ComfyUI/custom_nodes
    git clone https://github.com/YMC-GitHub/ymc-node-suite-comfyui
    

    Restart after installing. Four tiny pure-Python PyPI helpers self-install; no models, no GPU cost.

    Gotchas

    • It compares rounded values, not exact ones. text = "1.4" vs isRoundTo = "1": int(round(1.4)) is 1, which equals int(round(1)), so the match is True. The half-way cases are the trap: Python rounds 1.5 to 2 (banker's rounding), so "1.5" vs "1" returns False. If you need strict equality, this isn't the node.
    • If your condition source is already a real BOOL, skip this node and use the plain switch a and b - the string dance is only worth it when the value genuinely arrives as text.
    • WAS-conflict reminder: if WAS Node Suite is installed alongside, Manager may flag shared node names between the packs; disable one if you see save-node conflicts.
    Categoryymc suite/text/plain

    Inputs (4)

    NameTypeDefaultDescription
    aSTRING
    bSTRING
    textSTRING1
    isRoundToSTRING1

    Outputs (1)

    NameTypeDescription
    textSTRING