The new NodeBox forum is live! Everything from support.nodebox.net moved here: sign in with the same email to pick up your old posts. Something not working? Write to forum-support@nodebox.net.
One of the biggest hurdles I've encountered in learning Nodebox is the paucity of documentation. The node reference offers little more than a bare list of ports. Thank goodness for the tutorials and the generous people on the forum!
The most frustrating node for me was Format Number. All it says about how to format numbers is "Format: The format template". That's it. Not even a clue as to which of the many different format coding systems NodeBox uses. When I needed to format some numbers to always show a + sign, add commas, and put a percentage sign at the end I tried many guesses at different incantations without ever hitting on the magic formula.
The only clue was the percentage sign at the front of the hint text of the template field. This rang a distant bell. A long web search eventually turned up the old string format operator used in early versions of Python (pre-2.6). I now think this is what Nodebox still uses.
Here, for fellow newbies, is an old web page which documents this system:
Could you confirm that this is correct? If it is, perhaps you could add this (or some better) link to the documentation for the Format Number node.
Thanks!
John
FB
FBFrederik De BleserNodeBox team
You're right, we could do a lot better in that regard.
The format number node uses Java's String.format function. Here is the documentation. I've added the link on the reference as well.
However, we can still do better, showing some examples of where and how you might use it. An example of where the documentation is a bit longer is the keys node.
JO
JOjohn
Thanks Frederik!
One thing. Since the Format Number node insists on a floating point input, it doesn't seem to allow any non-floating conversions. So even if I feed it an integer, it won't allow '%x' to convert it to hex.
Is this correct? If so, is there some other (easy) way to convert an integer to a hex value? I could do this by stringing together mods, substrings, and a concatenate or by making a custom node but I'd hoped for something less messy.
Thanks,
John
FB
FBFrederik De BleserNodeBox team
That’s tricky. The format number always converts to floating-point first, internally, so there’s no good way to use that.
I think your best bet is to write a custom node. The code for this (in Python) is rather simple
def to_hex(v):
return hex(v)
This will return something like “0xab456”. If you don’t want the “0x” at the front, use:
def to_hex(v):
return hex(v)[2:]
Grtz,
F
Know something that helps?
Sign in with your email address to reply. No password needed.