Sprintf with "new" numbers

There have been some posts how to handle e.g. rounding of numbers in HABpanel now that numbers include units and sprintf can’t be used directly. The solution might very well have been posted elesewhere and there might be much better solutions, but this works for me:

{{'%.1f' | sprintf:itemState(config.PressureValue).split(' ')[0]}} {{itemState(config.PressureValue).split(' ')[1]}}

So as you see, the item state is split at the space between the value and unit (hopefully there is always a space there?!), the sprintf is then applied to the first part and after that a space (notice the space in }} {{) and finally the unit.

1 Like