{"record":{"id":"48df62a0b2975665","repo":"Comfy-Org/ComfyUI","slug":"cannot-convert-string-to-number-value-r","errorCode":null,"errorMessage":"Cannot convert string to number: {value!r}","messagePattern":"Cannot convert string to number: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_number_convert.py","lineNumber":60,"sourceCode":"    @classmethod\n    def execute(cls, value) -> io.NodeOutput:\n        if isinstance(value, bool):\n            float_val = 1.0 if value else 0.0\n            int_val = 1 if value else 0\n        elif isinstance(value, int):\n            float_val = float(value)\n            int_val = value\n        elif isinstance(value, float):\n            float_val = value\n            int_val = int(value)\n        elif isinstance(value, str):\n            text = value.strip()\n            if not text:\n                raise ValueError(\"Cannot convert empty string to number.\")\n            try:\n                float_val = float(text)\n            except ValueError:\n                raise ValueError(\n                    f\"Cannot convert string to number: {value!r}\"\n                ) from None\n            if not math.isfinite(float_val):\n                raise ValueError(\n                    f\"Cannot convert non-finite value to number: {float_val}\"\n                )\n            try:\n                int_val = int(text)\n            except ValueError:\n                int_val = int(float_val)\n        else:\n            raise TypeError(\n                f\"Unsupported input type: {type(value).__name__}\"\n            )\n\n        if not math.isfinite(float_val):\n            raise ValueError(\n                f\"Cannot convert non-finite value to number: {float_val}\"","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_number_convert.py#L42-L78","documentation":"Raised by the number-conversion node when float(text) raises ValueError, i.e. the stripped string is non-empty but not parseable as a float. The from None suppresses the chained float() traceback so only the offending value is reported via {value!r}.","triggerScenarios":"Strings like 'abc', '1.2.3', 'NaNabc', '$5', or '1,000' (comma thousands separator) — anything Python's float() rejects. Triggered only in the isinstance(value, str) branch.","commonSituations":"Currency or comma-formatted numbers pasted from spreadsheets; text with units like '512px'; LLM- or template-generated strings that include prose; locale-formatted decimals.","solutions":["Send a plain decimal string: '3.14', '-2', '1e5'.","Strip units/symbols/commas upstream ('1,000' -> '1000', '512px' -> '512').","For values that may legitimately be NaN/Inf, resolve them upstream — this node also rejects non-finite results (see error 944)."],"exampleFix":"// before\nNumberConvert(value=\"1,024px\")\n// after\nNumberConvert(value=\"1024\")","handlingStrategy":"validation","validationCode":"def to_float_or_none(text: str):\n    try:\n        return float(text.strip().replace(',', ''))\n    except ValueError:\n        return None\n\nval = to_float_or_none(raw)\nif val is None:\n    raise ValueError(f\"upstream produced non-numeric text: {raw!r}\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize comma thousands separators and strip units/symbols before conversion.","Prefer numeric primitive nodes over free-text strings for numeric workflow values."],"tags":["type-conversion","string","number","parse-error"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}