Memory use bar-card

Hello,

I’m building a bar-card in order to monitor the memory use of the Odroid board where I installed home assistant.
I used this portion of code, where I defined a config card template with the variables:

id: odroidn2_status
type: custom:config-template-card
variables:
  - states['sensor.home_assistant_host_disk_total'].state
  - states['sensor.home_assistant_host_disk_used'].state
  - states['sensor.system_monitor_memory_use'].state
  - states['sensor.home_assistant_core_cpu_percent'].state
  - states['sensor.system_monitor_processor_temperature'].state
entities:
  - sensor.home_assistant_host_disk_total
  - sensor.home_assistant_host_disk_used
  - sensor.system_monitor_memory_use
  - sensor.home_assistant_core_cpu_percent
  - sensor.system_monitor_processor_temperature

and this one where I defined the name of the card:

- type: custom:bar-card
              show_icon: true
              icon: mdi:memory
              align: split
              columns: 1
              max: 100
              positions:
                icon: outside
                indicator: inside
              unit_of_measurement: '%'
              severity:
                - color: '#3f921b'
                  from: 0
                  to: 49.9
                - from: 50
                  to: 74.9
                  color: '#c5af1a'
                - from: 75
                  to: 94.9
                  color: '#ffa500'
                - from: 95
                  to: 100
                  color: '#ff0000'
              card_mod:  
                style: |
                  ha-card {
                    --ha-card-border-width: 0px;
                  }
                  bar-card-currentbar, bar-card-backgroundbar{
                    border-radius: 10px;
                  }
                  bar-card-name {
                   font-size: 11px;
                  }
              entities:
                 - entity: sensor.system_monitor_memory_usage
              name: ${ 'RAM (' + vars[2] + 'Gb/4 Gb)' }
              entity_row: true

But the card shows me the following:

image

Is there a way to avoid that long number and keep “1.9” or at least “1.95”? How could I round into the name bar-card?

What is the precision set to in the sensor’s settings?

Here you are:

image

This should work

name: ${ 'RAM (' + Math.round(vars[2]) + 'Gb/4 Gb)' }

Great! It worked, thank you.
Now, If I would want to choose the number of decimals, what do I have to modify?

name: ${ 'RAM (' + Math.round(vars[2]*10)/10 + 'Gb/4 Gb)' } will get you 1 digit
example 1.7

name: ${ 'RAM (' + Math.round(vars[2]*100)/100 + 'Gb/4 Gb)' } will get you 2 digits
example 1.67

and so on…

Thank you very much. It worked perfectly.
But now I have many decimal numbers for another bar-card … it seems that every inegration works differently from the other ones.
I’m doing the same card for my Qnap NAS, so the section in which I declared the variables now it’s this:

id: qnap_status
type: custom:config-template-card
variables:
  - states['sensor.nas0adaa6_drive_0_1_temperature'].state
  - states['sensor.nas0adaa6_drive_0_2_temperature'].state
  - states['sensor.nas0adaa6_drive_0_3_temperature'].state
  - states['sensor.nas0adaa6_drive_0_4_temperature'].state
  - states['sensor.nas0adaa6_spazio_utilizzato_datavol1'].state
  - states['sensor.nas0adaa6_volume_used_datavol1'].state
entities:
  - sensor.nas0adaa6_drive_0_1_temperature
  - sensor.nas0adaa6_drive_0_2_temperature
  - sensor.nas0adaa6_drive_0_3_temperature
  - sensor.nas0adaa6_drive_0_4_temperature
  - sensor.nas0adaa6_spazio_utilizzato_datavol1
  - sensor.nas0adaa6_volume_used_datavol1

and the bar-card of disk used percentage is this:

- type: custom:bar-card
          show_icon: true
          icon: mdi:harddisk
          align: split
          columns: 1
          max: 100
          positions:
            icon: outside
            indicator: inside
          unit_of_measurement: '%'
          severity:
            - from: 0
              to: 49.9
              color: '#3f921b'
            - from: 50
              to: 74.9
              color: '#c5af1a'
            - from: 75
              to: 94.9
              color: '#ffa500'
            - from: 95
              to: 100
              color: '#ff0000'
          card_mod:
            style: |
              ha-card {
                --ha-card-border-width: 0px;
                }
              bar-card-currentbar, bar-card-backgroundbar{
                border-radius: 10px;
              }
          entities:
            - entity: sensor.nas0adaa6_volume_used_datavol1
          name: ${ 'Disk (' + math.round(vars[4]*100)/100 + ' TB/' + '9 TB)' }
          entity_row: true

You can see the math.round function I used to fix the previous issue, but now the issue I get on the declared entity “sensor.nas0adaa6_volume_used_datavol1” that gives me the percentage but in the following way:

image

Tried to use math.round but in this case (obviously) doesn’t work. What do I have to use to get 2 decimals, or one or anyone?

Add decimal here…

entities:
            - entity: sensor.nas0adaa6_volume_used_datavol1
              decimal: 2
          name: ${ 'Disk (' + math.round(vars[4]*100)/100 + ' TB/' + '9 TB)' }
          entity_row: true

Very very nice. Thank you. Even this one was fixed!!