Number Format Pattern shows Negative Zero on Numeric Label Component

I have a floating-point value which I want to display as an integer. When the value is in the range [-0,-0.5] including both -0 and -0.5, it displays as “–0”, or a zero with a negative sign. It looks kinda funky. Any way to make that disappear? Also a little surprising that it treats the value “-0” differently from “0”. I suppose that’s because of floating-point differences. Regardless, imo it should be able to be worked around with the number format pattern.

image

Try converting your bound value to an integer using toInt() and see if that gives you the output you want.

Unfortunately, the decimal format pattern you see in the property editor is Java’s format pattern, and you can’t use it to work around this.

It’s a rounding issue, like you guessed. One work around would be to have your bound value as part of an expression that rounds to an int first (like @schenk suggested).

2 Likes

Thanks for the extra explanation Kathy, and confirmation that Java’s format pattern isn’t enough to handle this. Using toInt() causes [-0,-0.5] to round to “0”, which is then displayed as expected without a negative.

Let’s hope I never need to round to one decimal place and want to only show “0.0” instead of “-0.0”. I tested the round() function with -0.04, which rounds to -0.0 and thus still displays the negative. I suppose I could write a custom rounding function with toInt() to get around that, but let’s hope I just don’t need to :slightly_smiling_face:

If that’s the case, you can always use numberFormat({value}, '#.0')

1 Like