Nodes/LF Nodes/Convert to number
ComfyUI Node

Convert to number

Convert anything to a number — and get the sum for free

By lucafoscili·Created 2 years ago·Updated 2 years ago· 50
Convert to number
  • JSON
  • ui_widget
  • float
  • int
  • float_sum
  • int_sum
  • float_list
  • int_list
boolean
string
integer
float

ComfyUI is a typed graph, and type mismatches are half of every beginner's debugging session: you've got a JSON field that's actually a number, or a string that should feed a float input, and the connection just won't go. LF_Something2Number is the conversion node that absorbs all of it - it accepts JSON, boolean, string, integer, or float on its inputs and hands you numbers back on the other side. The "Something" in the name is doing real work: you don't have to know what you've got, you just route it through and it becomes numeric.

Every input is optional, so you connect whatever you actually have - a JSON value, a boolean, a string, an integer, or a float - and the node converts the ones that are connected. The outputs cover the cases: float and int for single values, plus float_list and int_list when the input expands into multiple values. And then the bonus outputs: float_sum and int_sum. If your input is a list (or you've connected multiple values), you get the total without adding a math node. That's the kind of output that's invisible until you need it, then you wonder why every converter doesn't have it.

Mechanically it's type coercion with sensible rules: booleans become 1/0 (useful more often than people admit), strings are parsed as numbers (a string "3.5" becomes the float 3.5), integers and floats pass through, and JSON scalars get unwrapped into their numeric form. The failures are the predictable ones - a string like "abc" that can't parse as a number won't convert, and that's the edge case to keep in mind if you're feeding it LLM output or OCR text. It's a "do the obvious thing" node, and the obvious thing is right most of the time.

Where this earns its place: cleaning up data from other nodes before it hits a parameter. Strings from a text node into a strength slider, booleans into an arithmetic node, JSON values from a loaded config into a math operation - this is the junction that makes those work without building a conversion chain of three nodes. It's also a fine example of why the LF pack gets recommended in general: the author's thing is "a frontend widget on every node and the conversions you always need," and this is a straight line to that.

Install is the pack standard: ComfyUI Manager → "LF Nodes", or git clone https://github.com/lucafoscili/comfyui-lf into custom_nodes, then restart. No models or dependencies. And the standing note for this pack: comfyui-lf is legacy/frozen (fully functional) while active work happens in lucafoscili/lf-nodes - the same converter lives there.

Category✨ LF Nodes/Primitives

Inputs (6)

NameTypeDefaultDescription
JSONoptJSONJSON value to convert to numbers.
booleanoptBOOLEANBoolean value to convert to numbers.
stringoptSTRINGString value to convert to numbers.
integeroptINTInteger value to convert to numbers.
floatoptFLOATFloat value to convert to numbers.
ui_widgetoptKUL_CODE

Outputs (6)

NameTypeDescription
floatFLOAT
intINT
float_sumFLOAT
int_sumINT
float_listFLOAT
int_listINT