Nodes/ComfyUI-Light-Tool/Light-Tool: Convert Num Type
ComfyUI Node

Light-Tool: Convert Num Type

Force a number into the type your node insists on

By ihmily·Created 2 years ago·Updated 4 months ago· 20
Light-Tool: Convert Num Type
  • number
  • number
return_typeINT

Light-Tool: ConvertNumType is the type-coercion adapter for numbers: take any numeric value and hand it back as an integer, a float, or a string. It exists because ComfyUI's type system is strict even when you, the human, are not - a node will happily refuse a perfectly good number if it arrives as the wrong type.

This is the kind of node you install without fanfare and then use constantly without noticing. The Calculate node gives you three typed outputs precisely because type mismatches are such a common graph-killer. This node is the general-purpose version of that idea: whatever you've got, force it into the shape the next node wants.

How it works

One input, one toggle:

  • number - the value to convert. It accepts actual numbers or numeric strings (so text coming out of a Show Text or a JSON parse works fine).
  • return_type - pick INT, FLOAT, or STRING.

The conversion itself has one behavior worth memorizing: INT rounds, it doesn't truncate. float("3.7") → INT gives you 4, not 3. If your downstream math assumed truncation, that rounding can quietly shift a computed dimension by a pixel or two. For most cases it's the nicer behavior - and if you specifically need floor/ceiling, round the value yourself before it lands here.

Output is a single number of the requested type.

When you'll actually use it

  • STRING → INT/FLOAT. A value extracted from a JSON string or a text field arrives as text; punch it through to a number so it'll fit an INT widget on another node.
  • FLOAT → INT. Downstream nodes that demand whole-pixel dimensions will reject a float; convert rather than hand-typing a rounded value.
  • Any → STRING. For concatenation or display when you're building a text summary.

It's the connective tissue between the pack's data nodes: DeserializeJsonStringKeyValue-style extraction → this node → a numeric input on an image or sampling node. A whole class of "I have the number but the node won't take it" errors just disappears.

Gotchas

The only failure mode is feeding it something that genuinely isn't a number - convert a string like "hello" and the cast raises. It's a hard error with no graceful fallback, so guard the input if it could be garbage. And remember the INT-rounds behavior when you're doing precise dimension math. Otherwise this is about as low-risk as a node gets: nothing to configure beyond the toggle, no models, no side effects.

Install

Standard: ComfyUI Manager → search ComfyUI-Light-Tool, or clone into custom_nodes, pip install -r requirements.txt, restart. It's under ComfyUI-Light-Tool → DataProcessing.

CategoryComfyUI-Light-Tool/DataProcessing

Inputs (2)

NameTypeDefaultDescription
number*
return_typeCOMBOINT3 options: INT, FLOAT, STRING

Outputs (1)

NameTypeDescription
number*