ComfyUI Node

round

Rounding in ComfyUI is way more annoying than it should be. This is the fix.

By StableLlama·Created about a year ago·Updated 4 days ago· 48
round
    • FLOAT
    float_value0.00
    decimal_places2

    The fastest way to discover you need a round node is to compute an upscale factor and watch it come out as 1.4999999999999998. That trailing garbage isn't a bug in your workflow, it's just floating-point arithmetic being floating-point arithmetic - and once it lands in a filename, a resolution, or a string you paste into a prompt, it's ugly. round (class FloatRound) is the pack's answer: feed it a float, tell it how many decimals, get a clean float back.

    It's one node out of Basic data handling, StableLlama's dependency-free utility pack. This particular node is the boring kind of useful - you won't build a workflow around it, but you'll keep a couple around for every time a ratio or multiplier spits out 17 digits.

    How it works

    It's a straight call to Python's built-in round(float_value, decimal_places) - nothing fancy, no custom rounding library, nothing that can break. Which means it also inherits Python's quirk: banker's rounding. Values exactly halfway between two candidates round to the even number, so round(2.5) gives you 2, not 3, and round(3.5) gives you 4. If you're rounding weights or ratios and the half-values matter, this will surprise you exactly once; for typical use (cleaning up a 1.4999999) it's irrelevant.

    The inputs and the output

    Only three things on the node, all obvious:

    • float_value (FLOAT, default 0) - the number to round.
    • decimal_places (INT, default 2, minimum 0) - how many digits after the point you want. Set to 0 and it rounds to a whole number.
    • FLOAT (output) - the rounded value, still a float.

    Note that even with decimal_places at 0 you get a FLOAT out, not an INT. If the downstream node wants an integer, either set decimal_places to 0 and then cast with the pack's to INT, or just wire it and let ComfyUI coerce - but know the difference between rounding and truncating (see below).

    Installing it

    Grab Basic data handling through ComfyUI Manager (search "Basic data handling"), or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
    

    Restart ComfyUI. Zero Python dependencies, zero model downloads - this pack can't break your environment.

    Troubleshooting

    • "It rounded up when I expected down" (or vice versa) - that's probably banker's rounding, above, or you're confusing this with truncation. round(1.999, 0) is 2.0; int(1.999) is 1. Different operations, different nodes.
    • Rounding for a seed? Seeds need INTs and you'll usually want to round then cast, because some nodes reject floats where an int belongs. Round first, cast second - casting a raw float like 42.9 to INT truncates it to 42 and quietly drops your intent.
    • Negative decimal_places can't happen through the UI (min is 0), but it's worth knowing round(1234.5, -2) would round to the hundreds - you won't hit it here.
    CategoryBasic/FLOAT

    Inputs (2)

    NameTypeDefaultDescription
    float_valueFLOAT0.00
    decimal_placesINT2

    Outputs (1)

    NameTypeDescription
    FLOATFLOAT