How to create fixed decimals in a sensor

In this forum I did check how to create fixed decimals at a sensor value.
I did found the format extension and tried that like:

    magnetron_energie_today_euro:
      friendly_name: "Kosten magnetron vandaag"
      unit_of_measurement: "€"
      icon_template: "mdi:currency-eur"
      value_template: "{{ '{:.2f}'.format(((states('sensor.magnetron_energie_daily') | float) * (states('sensor.dsmr_day_consumption_energy_supplier_price_electricity_delivered_1') | float)) | round(2)) }}"

Using: ‘{:.2f}’.format for formatting two decimals
But it stil gives:

What am I doing wrong?
Thanks for the help

If paste it into templates do you see what you want

Off top head in your profile there a number format setting

Thanks for your answer. I didn’t think about that.
There it shows indeed a template of 2 decimals:

image

But in the card not

Which card are you using? Doesn’t look like plain “entities”.
It might itself do a conversion to float, which would make your forcing to 2 decimals useless.

My Yaml code looks like this:

 ## Magnetron
      - cards:
          - name: Magnetron
            styles:
              card:
                - text-transform: uppercase
                - font-size: 125%
                - color: 'var(--dwains-theme-accent)'
                - border-radius: 0%
                - font-weight: 100
                - letter-spacing: 10px
                - --mdc-ripple-press-opacity: 0
                - cursor: initial
            type: 'custom:button-card'
          - cards:
              - entities:
                  - color: 'var(--dwains-theme-accent)'
                    entity: sensor.bw_8_magnetron_power
                    name: Huidig energieverbruik (24h)
                font_size: 80
                hours_to_show: 24
                line_width: 2
                hour24: true
                points_per_hour: 2
                decimals: 0
                show:
                  animate: true
                  fill: true
                  icon: false
                  labels: false
                  name: false
                  graph: line
                  extrema: true
                  average: true
                theme: ios-dark-mode-blue-red
                type: 'custom:mini-graph-card'
              - aspect_ratio: 1/1.2
                color: 'rgb(150, 150, 150)'
                entity: switch.bw_8_magnetron
                icon: 'mdi:microwave'
                name: Magnetron
                show_state: true
                size: 30%
                lock:
                  enabled: true
                  #enabled: '[[[ return entity.state === 'on'; ]]]'
                  duration: 10
                  unlock: hold
                  #exemptions:
                  #  - username: test
                state:
                  - color: var(--disabled-text-color)
                    value: 'off'
                    icon: mdi:microwave-off
                  - color: 'var(--dwains-theme-accent)'
                    value: 'on'
                styles:
                  name:
                    - text-transform: uppercase
                    - font-size: 10px
                  state:
                    - text-transform: uppercase
                    - font-size: 15px
                    - font: bold
                type: 'custom:button-card'
            type: horizontal-stack
          - entities:
            - entity: sensor.magnetron_energie_daily
              name: Verbruik vandaag
            - entity: sensor.magnetron_energie_today_euro
              name: Kosten vandaag
            - type: custom:fold-entity-row
              head:
                type: section
                label: Meer informatie
              entities:
                - entity: sensor.magnetron_energie_yesterday
                  name: Verbruik gisteren
                  icon: mdi:counter
                - entity: sensor.magnetron_energie_yesterday_euro
                  name: Kosten gisteren
                - entity: sensor.bw_8_magnetron_kwh
                  name: Totaal energie verbruik
                  secondary_info: last-updated
            type: entities
        type: vertical-stack

It’s about the entities

I’m pretty sure the number gets converted to float, maybe at localization level.
You might want to try playing with those settings.

image

Thanks again. I will try

I tried. to change as you mentioned but no change unfortunately.
The strang part is that if not using the format template it shows 1 digit in result:

and using format template it says two digits in result:

but in the card at frontend it is not showing two digits:

That is what i’m confused about

Change number format in user part as you mentioned is not effect the result also

1 Like