Rounding in var declaration for custom:button-card to avoid epsilon error

HI everyone,

I am struggling with the following epsilon error and cannot find a work around…I wonder if you can help
I am creating the following custom button card showing few info for my NAS.
As you can see the free space % comes out with the epsilon error…
image

here the code I am using for that specific field:

        custom_fields:
          vol: |
            [[[
             var free_disk = 100 - states['sensor.torakiki_volume_used'].state;
             return `<ha-icon
             icon="mdi:server"
             style="width: 12px; height: 12px; color: deepskyblue;">
             </ha-icon><span>Space left: <span style="color: var(--text-color-sensor);"><b>${free_disk}%</b></span></span>`
            ]]]

I have tried using float and rounding, but if I do so, the card is simply not showing anymore.

Any suggestion?

Thanks a lot

if you go to the developer tools → state and put in sensor ‘sensor.torakiki_volume_used’ what does it show? Is it an integer?

You can try:


  [[[
     var used = states['sensor.torakiki_volume_used'].state
     var free = 100 - used
     var free_disk = Number((free).toFixed(2))

     return `<ha-icon
     icon="mdi:server"
     style="width: 12px; height: 12px; color: deepskyblue;">
     </ha-icon><span>Space left: <span style="color: var(--text-color-sensor);"><b>${free_disk}%</b></span></span>`
  ]]]

this worked like a charm!!! thanks a lot - I will study the code…I am not familiar with this

I get 65.4