ComfyUI Node

Round Float

Round floats the way a schoolchild would, not the way a banker would

By LaVie024·Created about a year ago·Updated 8 months ago· 8
Round Float
    • rounded_float
    input_float
    decimal_places1

    You'd think rounding a float would be a solved problem, and then you hit Python's built-in round(), which does banker's rounding: round(2.5) gives you 2, because it rounds ties to the nearest even number. That's correct for statistics and infuriating for everything else. RoundFloat is the node that does what humans actually expect - half goes up, away from zero - and it lets you pick how many decimal places to keep.

    Why you'd reach for it

    Sampling parameters drift all over the place in real workflows. Your CFG slider produces 7.4499999, your denoise value comes out of a math chain as 0.8200001, and somewhere downstream you need clean numbers - for metadata, for a display node, for a filename that's going to look ridiculous with seventeen decimal places. RoundFloat is the clean-up step between "a float exists" and "a float I'm willing to show anyone." It's the kind of node you add once, forget about, and then quietly miss in every other pack.

    How it works

    The implementation is worth a glance because it explains the behavior exactly. It multiplies by 10^decimal_places, adds 0.5, floors the result, and divides back - with the sign preserved via copysign. That's classic round-half-away-from-zero: 2.5 rounds to 3, -2.5 rounds to -3, and 2.45 to one decimal place becomes 2.5. No banker's rounding, no truncation, no floating-point ties deciding the direction. The author's README calls this out deliberately, and it's the right call for this domain.

    The inputs and output

    • input_float (FLOAT, forced input) - the value to round. It's marked forceInput, so you're expected to wire it rather than type into a box.
    • decimal_places (INT, default 1, min 0) - how many digits to keep. Zero gives you a whole number. The schema doesn't cap it, so be sensible.
    • rounded_float (FLOAT) - the result. Note it stays a float even when decimal_places is 0, so don't assume you're getting an int.

    That's the whole node. Two inputs, one output, no configuration beyond the decimal count.

    Installing it

    Part of comfyui-lopi999-nodes, installable like everything else in the pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/LaVie024/comfyui-lopi999-nodes
    

    Then restart ComfyUI, or use ComfyUI Manager and search "comfyui-lopi999-nodes." No model downloads, no extra pip dependencies for this node.

    Common issues

    The main gotcha is floating-point representation doing its usual thing: rounding 0.1 + 0.2 to one decimal place gives you 0.3 correctly because of the add-0.5-and-floor trick, so this node handles it better than naive round() would. Don't expect binary-exact decimals from any float node, though - if you need exact arithmetic, this isn't the tool. And if your rounded value still looks wrong, double-check which node upstream is actually producing the input_float: forceInput means the wire you attach is the only thing that matters.

    Categorylopi999/logic

    Inputs (2)

    NameTypeDefaultDescription
    input_floatFLOAT
    decimal_placesINT1

    Outputs (1)

    NameTypeDescription
    rounded_floatFLOAT