Formatting of values in UI / state vs displaystate

I have some issues with displaying numeric values in the main UI. While some values look nicely formatted others are shown with way to many decimal places (see screenshot)

The values are shown as text of an f7-chip component by accessing the state property of an item. I already tried to use displaystate instead and defined the corresponding metadata for the items. However that did not work reliably. Sometimes it was displayed correctly and sometimes no value at all. A refresh
sometimes helped.

Why are some values already formatted nicely without specifying any additional formatting hint and others not? Where is this configured?

Additional observation:
I have at least one item that reproducible has no displayState property although the StateDescription Metadata is defined and is also respected when checking the item in the administrative UI for that item.

displayState will not be present if it has the same value as state, please check

@crnjan has the explanation for why there isn’t always a displayState even when there is a State Description.

As for why some values appear formatted and others not? Have you looked to see what the state of the formatted ones are? I bet you’ll find that they match what is shown and don’t have as many decimal places. When ever you have a value that is the result of a calculation you will often have lots and lots of decimal places due to the fact that some numbers simply cannot be represented in a floating point number. Instead you end up with a value that’s really close which means lots of decimal places.

Thanks for your explanations. Knowing that displayState is only there if it differs from the state explains why it was sometimes there and sometimes not.