Nodes/ComfyUI-HappNodeSet/Number String Cleanup
ComfyUI Node

Number String Cleanup

Rescuing '52,25 €' and other human-typed numbers from text output

By mikemojen·Created 8 months ago·Updated 3 months ago· 0
Number String Cleanup
    • cleaned_number
    raw_string

    LLMs and text tools are great at producing numbers that aren't numbers: "52,25", "$1,299.99", "approx. 42.7 px", or a digit followed by a stray letter. Number String Cleanup exists to turn that mess into a clean, two-decimal-place number string. Feed it a raw string, get back something you can actually parse - this is the node you put between a text-output node and anything that needs a real numeric value.

    How it works

    The cleaning pipeline is a series of practical fixes: strip whitespace, delete everything that isn't a digit, comma, dot, or minus sign; then replace the first comma with a dot (so European "52,25" becomes 52.25); if multiple dots survive, keep only the last one as the decimal separator (so 1,299.991299.99); handle a leading minus; then convert to float and format to two decimals. Edge cases are handled gracefully - empty input, a lone ., -, or -. all return "0.00" rather than an error.

    It's worth knowing what this node does not do: it won't fix "1.299,99" (the Brazilian/Portuguese format, where the dot is a thousands separator and the comma is the decimal point) - that pattern gives you 1.29999 after the comma-to-dot swap, a very wrong number. It's built for the formats the author's workflows produced, which is US/European style, and for everything else you'll want to normalize the separators yourself first.

    What comes out

    A single cleaned_number (STRING) - always exactly two decimal places, e.g. "52.25" or "0.00". Note the output is a string, not a float: if you need a numeric value, feed this into a string-to-float conversion node, or use the pack's CSV Value Extractor which returns a real FLOAT.

    Where it fits

    Any place where a model or a text-based node returns numbers as prose: paste-in of OCR output, LLM chat responses, values extracted from a caption. In this pack's context, it's a natural cleanup step after anything that hands back a measurement string with stray characters - pair it with CSV Value Extractor if you're dealing with a comma-separated list that also needs per-value cleanup.

    Install

    Part of ComfyUI-HappNodeSet (mikemojen). ComfyUI Manager: search HappNodeSet. Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/mikemojen/ComfyUI-HappNodeSet.git
    pip install -r ComfyUI-HappNodeSet/requirements.txt
    

    Restart ComfyUI. Pure Python regex - zero extra dependencies beyond the pack's requirements.

    Common issues

    The two traps are the format assumptions above: European comma-decimal works, but the mixed 1.299,99 style doesn't, and neither does a number with spaces as thousands separators (1 299 gets its spaces stripped into 1299, which happens to be fine - but 1 299,5 becomes 1299.5, which is right). If you're feeding it numbers with units, the unit is stripped, which is usually what you want - just don't ask it to tell you what the unit was. It's a tiny, opinionated helper: understand its two assumptions and it'll never surprise you.

    Categoryutils/string

    Inputs (1)

    NameTypeDefaultDescription
    raw_stringSTRING

    Outputs (1)

    NameTypeDescription
    cleaned_numberSTRING