Using a variable to specify number format in format()?

I need to support a variable number of decimal places depending on the CNC machine being targeted, but I can’t seem to find a way to use an input to Format, Expression, or Eval to do so:


variable-format.gh (4.6 KB)

Any clever ideas? This will be duplicated quite a bit so I’d rather not use a brute force stream gate or something.

Thanks!

With “Expression” component your function is static, to edit it you have to enter it with double click etc etc…
If, instead, you use “Evaluate” component, you’ll be able to feed it a string (your function)… and you can dynamically build that string.


variable-format.gh (10.5 KB)

Anyway, you can also just use Round(a,b) where b is the decimal places you want.

1 Like

Thanks – a little bummed that Eval’s replacement scheme (really .Net’s, I suppose) has that limitation.

I ended up using plain old Format; it is much much faster than either Eval or Expression. This was all an effort to replace a ton of Round’s and Concats which was even slower assembling about a million lines of gcode.

1 Like