ComfyUI Node

sum

Total up a list of numbers, as both int and float

By StableLlama·Created about a year ago·Updated a day ago· 48
sum
  • list
  • int_sum
  • float_sum
start0

Add up every number in a list and give me the total - that's DataListSum, Python's sum() as a node. But it does one thing most similar nodes don't: it hands you the total twice, once as an int and once as a float, so whatever the downstream node expects, one of them matches.

Inputs: list (of FLOAT or INT values) and an optional start (an INT, default 0) that gets added to the total - think of it as a running offset for the sum. Outputs: int_sum and float_sum, both representing the same total in their respective types.

How it works

The mechanism is plain sum(list, start), with the result cast to both int and float. Two behaviors to know:

  • Empty list gives 0, not an error and not None. That's stated right in the node's description and it's a sensible choice - a sum of nothing is zero.
  • The int output is a truncating cast: a total of 2.9 shows up as int_sum = 2. If you need the exact fractional value, take the float_sum wire; if you're feeding a count downstream, the int is probably what you want.

Why you'd reach for it

Summing is less glamorous than it sounds useful. Tally up total steps across a schedule, sum a batch of strength values to check you're not overshooting a budget, or just verify data integrity - "do these numbers add up to what I expected?" The dual outputs also remove a whole class of type-mismatch friction: wire float_sum into a node that wants a FLOAT, int_sum into one that wants an INT, no cast node needed in between.

Installing it

Part of StableLlama's Basic data handling pack - pure Python, zero dependencies, no model files:

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

Restart ComfyUI, or search "Basic data handling" in ComfyUI Manager and install. The pack has no third-party dependencies, so there's no install-time conflict roulette.

Common issues

The input port is typed FLOAT,INT, so strings won't sum - convert first. And watch the truncation on int_sum: if you expected rounding and got flooring, that's the node's documented behavior, not a bug (use float_sum for precision, or round it yourself). Finally, the empty-list-returns-zero rule means you can't distinguish "sum of nothing" from "sum that happens to be zero" - if that distinction matters, check the list length separately with DataListLength.

CategoryBasic/Data List

Inputs (2)

NameTypeDefaultDescription
listFLOAT,INT
startoptINT0

Outputs (2)

NameTypeDescription
int_sumINT
float_sumFLOAT