How can I get the "series"component to count with leading zeros?
Or how can I achieve leading zeros in a different way without blowing up the definition?
How can I get the "series"component to count with leading zeros?
Or how can I achieve leading zeros in a different way without blowing up the definition?
I tried that before but my numbers need to keep the same overall digit count. look what happens with numbers bigger than 9 or 09:
this will give 0βs before everything. You can do it with the Exprsion component and get the Format you require.
Both work, thanks a lot!
I need it for consisten filename output.
I forgot there is a dedicated component for this now. [Format]
You can read up more on the notation masks here: https://www.grasshopper3d.com/forum/topics/formatting-numbers-in-grasshopper
Even better, thanks a lot!
For some strange reason neither the Format component, nor the Expression component work for me as shown above. Well they did for one brief moment, but now it doesnβt show the leading zero anymore.
So I had to hack this:
I do found a better algorithm that can add leading zeros to any length of numbers.
Leading_Zero_new.gh (12.6 KB)
hi
You should edit multiline your β0β panel
Sorry mate, we are talking here about something totally different thing.
One line of Python:
a = N.zfill(len(L))
Nice one. Unfortunately it works only to generate new numbers but not if you need to add Leading Zeros to existing ones.
It works exactly as intended, your understanding is flawed.
zfill_2024Sep17b.gh (6.0 KB)
zfill_2024Sep17c.gh (4.6 KB)
You could modify Python to this if you prefer, but βLβ input requires Type Hint βintβ:
a = N.zfill(L)
zfill_2024Sep17d.gh (4.9 KB)
The idea is to find an algorithm that can fill the necessary leading zeroes AND to adapt automatically to the length of the input data without the need to specify manually the length.
a = N.zfill(L)
version:
My version βSep17bβ reply yesterday did that and was simpler.
Oh yeah, looks like I skipped by mistake. Thank you.
If youβre going the pythonic route:
mxlen = len(str(max(N)))
if not prefix: prefix = ""
a = [prefix+str(i).zfill(mxlen) for i in N]