Fixed number of digits in official gauge card (e.g. 1,00 €)

I have a sensor which returns a NUMBER (not string). How can I ensure that is displayed with e.g. 2 fixed decimals in a gauge card?

Example:

template:
  - sensor:
    - name: "Solar Accounting Total Daily"
      unique_id: solar_accounting_total_daily
      device_class: monetary
      unit_of_measurement: "EUR"
      state: >
        {{ ( ... | float(0)) | round(2) }}

Alternative:

      state: >
        {{ '%0.2f' | format( ... | float(0)) }}

With both ways the sensor apparently returns a NUMBER (not string) - which is actually what I want. But with that, 1.00 becomes 1 and 1.20 becomes 1.2. Only 1.23 stays the same. In consequence, when I put this sensor into a gauge card the trailing 0s are also gone. What I am actually after is a way to tell the gauge card that it should always display the monetary number with 2 fixed decimals, e.g. 1,00 €.

If this is not possible, what other options do I have?

I think that because given it a unit of measurement, then its considered a number and it gets treated like that.
The solution might be to remove that line and prevent it from being a number.

States are always strings. You can convert a state to a number in a template to perform mathematical operations but it will still be stored as a string.

Open a front end feature request, here:

Opened a feature request as advised:

Please vote if you need the same.

2 Likes

Have the same issue and voted the FR up
pretty annoying