The Format Number Template
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.
Comments are currently closed for this discussion. You can start a new one.
|?||Show this help|
|ESC||Blurs the current field|
|r||Focus the comment reply box|
|^ + ↩||Submit the comment|
You can use
Command ⌘ instead of
Control ^ on Mac
Support Staff 1 Posted by Frederik De Ble... on 25 Feb, 2015 08:35 PM
You're right, we could do a lot better in that regard.
The format number node uses Java's
String.formatfunction. 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.
Support Staff 2 Posted by john on 26 Feb, 2015 02:16 AM
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.
Support Staff 3 Posted by Frederik De Ble... on 28 Feb, 2015 10:13 AM
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
This will return something like “0xab456”. If you don’t want the “0x” at the front, use:
john closed this discussion on 02 Mar, 2015 03:40 AM.