#Rounding to fixed decimal for currency

1 messages · Page 1 of 1 (latest)

elder stag
#

I have this template ${{(float(states('sensor.house_power_consumption')) * 0.000300608) | round (2, "ceil") }}/hr which is fine in most cases, for values like 1.23, but when it rounds to a tenth, like 1.2, my result is $1.2/hr but I want it to display $1.20/hr. I've been trying to read the documentation on the format function, but it's doing my head in. It's trivial in out languages, and I am sure it is trivial here too, but how?

signal badger
#

Home assistant will always truncate trailing zeros

#

'${0:1.2f}/hr'.format(...) might get you what you want.

elder stag