ComfyUI Node

数值

QG_Number Saves You the Choice

By live1617·Created 15 days ago·Updated a day ago· 3
数值
    • value
    ◄kind整数►
    ◄value0.00►

    Here's a small annoyance that costs more time than it should. You drag a value out of a widget - the seed on a sampler, the steps count, the width - and now you need a node that holds that number so five things can read it. So: PrimitiveInt? Or PrimitiveFloat? You pick one, wire it, then discover the thing you're feeding wants the other type and ComfyUI won't let the wire connect because a FLOAT socket is not an INT socket.

    QG_Number collapses that decision into a gear icon. It's one card that holds one number, and a switch in the title bar decides whether that number goes out as an integer or a float.

    What it is, mechanically

    The backend declares two required inputs, both hidden behind the painted card:

    • kind - an enum with two options, 整数 (integer) and 浮点 (float). You change it from the gear menu left of the ? in the title bar.
    • value - a FLOAT, range roughly ±1e12, step 0.01. The card renders it as a draggable scrub box: drag sideways to change, click to type, arrows to step, Shift for fine steps.

    The output is named value and declares its type as * - ComfyUI's wildcard/"ANY" type. That's not laziness, it's the only option available: RETURN_TYPES is a class-level static declaration, fixed at load time, while the actual type here is chosen at runtime by kind. So the declaration says "anything" and execute() decides: float mode returns a float, integer mode returns a rounded int. The front end just relabels the output socket so you can see which one you're getting.

    The value widget always stays a FLOAT internally, even in integer mode. That's a deliberate call in the source and it saves you a stupid bug: flipping to integer and back doesn't swap which widget you're editing or change how the node serializes.

    Why bother

    Two practical wins. First, one node instead of two competing primitives - the pack's own framing, and it's right. A workflow full of PrimitiveInt/PrimitiveFloat nodes is a workflow where you keep picking the wrong one.

    Second, and more useful: the randomize/fixed/step ritual. The plumbing doc's most-repeated warning is the seed trap - the widget shows the seed for the next run, not the one that made the image you're looking at, because the control fires after generation. A dedicated number card with an explicit value is how you pin that number down deliberately, especially once you set the global "widget control mode" to Before in settings and stop losing seeds entirely.

    It's also the clean partner to the pack's math node: feed QG_Math a width and a height here rather than retyping constants into an expression.

    Inputs and outputs that matter

    Honestly, the only field a beginner touches is value. Drag it, done. kind is worth a glance once: if you're feeding something like a resolution or a frame count, integer is what you want, and integer mode rounds the decimals away rather than letting a 1024.4 sneak downstream. If you're feeding a strength, a CFG, a scale factor, float.

    Output is value, and it fans out to as many numeric inputs as you want.

    Installing

    This is part of ComfyUI-QG-tools, a 32-node utility pack. Zero pip dependencies - the repo's requirements.txt contains nothing but comments on purpose, so Manager won't try to install anything.

    cd ComfyUI/custom_nodes
    git clone https://github.com/live1617/ComfyUI-QG-tools
    

    Restart ComfyUI completely afterwards; the console banner ("QG-tools v0.9.4 | 32 nodes loaded") is your confirmation. The node lives under QG-tools/逻辑 and answers to a search for number, int, float or 数值.

    Traps

    The wildcard output means it will connect to anything. That's the price of the runtime type switch. ComfyUI won't stop you from dragging the output into an IMAGE input, because the node told the engine its output type is * and the engine takes that at face value - wildcard sockets are explicitly "up to the node to make sense of the data". Your mistake surfaces as a confusing error downstream instead of a wire that simply won't snap. Treat the output socket's label as the authority, not the engine's permission.

    Integer mode is a rounding operation, not a display toggle. Switch from 4.7 to integer and you have 5. Switch back to float and you have 5, not 4.7. The source calls this out as intentional - no "shows 4, actually 3.7" limbo - but if you were counting on the decimals being preserved, they aren't.

    It's a value node, not a calculator. For "width divided by two, rounded to a multiple of 8" you want the pack's math node; this one just holds a number you typed.

    CategoryQG-tools/逻辑

    Inputs (2)

    NameTypeDefaultDescription
    kindCOMBO整数这个数字是整数还是浮点数。在标题栏 `?` 左边的齿轮里切换;换成整数时小数部分会被四舍五入掉。
    valueFLOAT0.00-1000000000000–1000000000000数值。左右拖动改,单击可以直接输入,右边的上下箭头按步进调(按住 Shift 是细步进);整数模式下按 1 走。

    Outputs (1)

    NameTypeDescription
    value*—