Nodes/comfy-ovum/Convert any to INT and subtract 1
ComfyUI Node

Convert any to INT and subtract 1

Convert anything to an int, then knock one off — the off-by-one fixer

By sfinktah·Created about a year ago·Updated 10 months ago· 7
Convert any to INT and subtract 1
  • value
  • INT

Minus One is a one-job node with an unglamorous name and a surprisingly forgiving personality: feed it any value, it coerces that value to an INT, subtracts 1, and hands you the result. Its display name, "Convert any to INT and subtract 1", is the entire spec. There's a matching PlusOne in the pack, and together they're the kind of trivial-but-constantly-needed glue that keeps appearing in loop graphs.

Where do you actually use it? Off-by-one corrections, mostly. Loop indices start at 0 in this pack's loop nodes (MapStartOvum gives you index starting at 0), but filenames and human-facing counters usually want to start at 1 - so you PlusOne. Or you've got a list length from OvumLength and you need length - 1 to clamp an index or drive a range(stop) correctly, and Minus One is right there. It's also handy for converting a float widget (say a CFG from a UI slider that only outputs floats) into the exact integer you need.

How it works

The coercion is where it gets interesting, because it's smarter than a plain int(). Under the hood it uses the pack's coerce_any_to_int, which handles:

  • ints, floats, and booleans (truncated toward zero - 3.9 becomes 3),
  • strings that are plain integers ("42"),
  • strings containing basic math expressions ("3+2", "10/4", even 2**3) - it'll evaluate them safely first,
  • anything with a __len__, which means a string or a list gives you its length as the number to decrement.

Then it subtracts 1. That's the whole pipeline.

The inputs and outputs that matter

  • value (required, *) - anything you want coerced and decremented.
  • INT (output) - the result, always an INT.

Nothing else. There are no optional inputs, no mode toggles, no configuration. That simplicity is the appeal.

Installing it

Part of comfy-ovum (sfinktah). Install through ComfyUI Manager by searching "comfy-ovum", or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum

Restart ComfyUI after installing. No models to fetch; the pack's dependencies are light (pillow, numpy, requests, aiohttp and a few small extras), and Manager installs them for you.

Common issues

The gotchas are all in the coercion, not the minus-one. Floats truncate toward zero, so 2.99 minus one is 1, not 1.99 - if you need rounding, round upstream. Strings that are neither integers nor parseable math expressions raise a ValueError and you'll see it in the console, not as a graceful fallback. And watch the length-based path: hand it a string that isn't numeric and it'll happily treat the string's length as the number, which is usually not what you meant. If in doubt, feed it a clean INT from a dedicated int node.

Categoryovum/loop

Inputs (1)

NameTypeDefaultDescription
value*

Outputs (1)

NameTypeDescription
INTINT