tag:support.nodebox.net,2012-11-01:/discussions/nodebox-2-3/5397-the-format-number-templateNodeBox: Discussion 2015-03-02T03:40:20Ztag:support.nodebox.net,2012-11-01:Comment/361336702015-02-25T20:35:41Z2015-02-25T20:35:41ZThe Format Number Template<div><p>You're right, we could do a <em>lot</em> better in that
regard.</p>
<p>The format number node uses Java's <code>String.format</code>
function. <a href=
"http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax">
Here is the documentation</a>. I've added the link on the reference
as well.</p>
<p>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 <a href=
"https://www.nodebox.net/node/reference/list/keys.html">keys
node</a>.</p></div>Frederik De Blesertag:support.nodebox.net,2012-11-01:Comment/361336702015-02-26T02:16:18Z2015-02-26T02:16:18ZThe Format Number Template<div><p>Thanks Frederik!</p>
<p>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.</p>
<p>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.</p>
<p>Thanks,</p>
<p>John</p></div>johntag:support.nodebox.net,2012-11-01:Comment/361336702015-02-28T10:13:04Z2015-02-28T10:13:04ZThe Format Number Template<div><p>That’s tricky. The format number always converts to
floating-point first, internally, so there’s no good way to
use that.</p>
<p>I think your best bet is to write a custom node. The code for
this (in Python) is rather simple</p>
<p>def to_hex(v):<br>
return hex(v)</p>
<p>This will return something like “0xab456”. If you
don’t want the “0x” at the front, use:</p>
<p>def to_hex(v):<br>
return hex(v)[2:]</p>
<p>Grtz,</p>
<p>F</p></div>Frederik De Bleser