[BUG] String Format Floats

Trying to use string format to format the field width, as well as a floating point number, I've run into a bug.

The tag I'm displaying is a float, but despite that I get a

IllegalFormatConversionException: f != java.lang.Integer

Error when using the tag directly in the stringFormat function.

"Level: "+stringFormat("%4.1f", toFloat({[default]SCP/Level}))+"  ft"

Produces the desired result, but

"Level: "+stringFormat("%4.1f", {[default]SCP/Level})+"  ft"

Results in the error, but still seems to format it correctly.

What's the data type of the tag?

EDIT: And, what is the input and desired output? You know the drill... :wink:

It's a float tag. I'm trying to constrain the field width so that numbers stay in-line when leading digits are dropped, rather than shifting to the left when the number is shortened (also shifting the unit label of ft.).

Like so:
instead of:
(using numberFormat())

Like I said, the formatting still seems to work, but I get the error.

This doesn't seem to happen if I add custom properties to the label, bind the tag to that property, and use that property in the expression binding for the text.

"Level: "+stringFormat({Root Container.Label 1.formatString}, {Root Container.Label 1.value})+"  ft"

Apologies for overlooking that.

Seems to work okay for me. v8.1.21.

stringFormat("Level: %,8.1f  ft", {[Test]tag1})


It seems to do the formatting okay for me as well, but I still get the error. And I get the error every time I re-open the window with the binding.

It might be the binding starting to evaluate and passing a null at the beginning. Maybe add a coalesce:

stringFormat("Level: %,8.1f  ft", coalesce({[Test]tag1},0))

at that point I may as well use the toFloat()

1 Like

Would be interesting to know why it's seeing an integer though. Is the tag data itself a float or is it scaled? Like 0-1000 scaled to 0-100.0 kind of thing.

Does the error happen on every value change as well as opening the window?

They're all memory float tags (for the test). No scaling, just straight values.

Looks like it's only when the window first opens.

Ok I was able to reproduce it.