to hex
Turn a float into its exact hex form — lossless text, no rounding
- STRING
Writing a float out as text is normally a lie. print(0.1) shows you 0.1, but the float you actually have is 0.1000000000000000055511151231257827.... to hex (Basic data handling: FloatHex) is the node that refuses to lie: it converts a float to its exact hexadecimal representation using Python's float.hex(), which captures the value bit-for-bit.
One input, float_value (FLOAT), and one STRING output. The result looks like 0x1.8p+1 (that's 3.0), 0x1.999999999999ap-4 (that's 0.1, exactly), or 0x0.0p+0 (that's 0.0). If you've never seen this format, don't be alarmed - it's the standard IEEE-754 float rendered in hex with a power-of-two exponent. The p is the exponent marker, like an e in scientific notation but for base 2.
Why this is genuinely useful and not just trivia
The headline feature: lossless round-tripping. Convert a float to hex, then run the string through this pack's from hex (FloatFromHex) node, and you get back exactly the same float - every bit. No %f formatting, no rounding to a few decimals, no drift. That makes hex the correct format when you need to store a number as text and read it back later without losing precision: save it to a file with the pack's save-STRING node, load it back next run, and it's identical.
It's also a precise debugging tool. Seeing 0x1.8p+1 tells you instantly that the value is exactly 1.5 × 2¹ = 3.0. If you're chasing a precision bug - "why is my value 2.999999999 instead of 3?" - the hex form shows you the exact stored value and whether two numbers that look equal actually are.
Installing it
Part of the Basic data handling pack by StableLlama. ComfyUI Manager → search "Basic data handling" → install → restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
then restart. No dependencies, no requirements.txt, no model downloads.
Troubleshooting
The output is a hex string, not a number - don't try to wire it into a FLOAT socket directly; that's what FloatFromHex is for. And don't expect hex to look "human friendly": 0x1.999999999999ap-4 is the point - it's exact, not pretty. If you want a readable decimal string for display, you want a formatting/rounding node instead.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| float_value | FLOAT | 0.00 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |