Int to Leading String
Padding numbers to filenames that sort correctly
- string
Int to Leading String takes a number and pads it with leading zeros so it becomes a fixed-width string. 7 with a minimum digit count of 4 comes out as "0007". It sounds like busywork until the moment your saved files refuse to sort properly - at which point it becomes the most important node in the workflow.
Why you'd reach for it
The classic failure: you're saving frame_1.png, frame_2.png … frame_10.png, and your file browser sorts them as frame_1, frame_10, frame_2. That's not a bug, that's lexicographic sorting - and it's why every production pipeline pads numbers. This node turns your frame counter into frame_0001, frame_0002, so filenames sort the way your eyes expect.
It's also handy for building string identifiers with a stable format: seed values, iteration numbers, batch IDs that need to be a consistent length for downstream parsing.
How it works
The function zero-pads the absolute value to min_digit_count digits, then re-attaches the minus sign if the number was negative. So -5 with a count of 4 becomes "-0005", not "000-5". Padding happens on the digits only - the sign never eats a character slot.
The inputs that matter
- integer - the number to convert. Full int32 range, defaults to
0. - min_digit_count - the minimum number of digits. Defaults to
1(no padding at all), and can go up to20. A count of3makes42become"042".
One output:
- string - the padded result. Feed it into a String Combiner or directly into a Save node's filename field.
Installing it
Part of the TinyBee pack. ComfyUI Manager → Install Custom Nodes → search "ComfyUI-TinyBee", install, restart. Manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/TinyBeeman/ComfyUI-TinyBee
You'll find it under 🐝TinyBee/Casting in the node menu. It uses only the Python standard library, so there's no dependency wrangling for this one.
Common issues
Two things trip people up. First, if min_digit_count is smaller than the number of digits in your number, nothing is cut off - 15000 with a count of 4 stays "15000". The count is a floor, not a ceiling. Second, the default of 1 means no padding happens until you change it, which catches a lot of people who assume the node pads by default. Set the count to how many digits you want the final filenames to have, and it'll sort correctly every time.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| integer | INT | 0-2147483648–2147483647 | — |
| min_digit_count | INT | 11–20 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| string | STRING | — |