2 Decimal places

Hi All,

I am trying to display the following template to 2 decimal places. i have tried a number of different syntaxes but can’t get it quite right.

 {{ [ states('sensor.costs1'),states('sensor.cost2')] | map('float') | sum | round(2) }}

All I am getting is x.x instead of x.xx

I believe I have to format it something along the lines of

{{ ‘%.2f’ | format((states(‘sensor.costs1’…

But I need to add the sensor values together and then format it to 2 deciaml places.

Thanks

|round(2) should work in most cases, however there is no way to stop home assistant stripping off trailing zeros other than to make your number a string.

Have a read of this topic Template sensor to state the last zero

1 Like

Perfect thanks Tom.