Slider getting strange value (non rounded)

hello,

I am running hassio 0.73.0

my 2 input_numbers are defined in input_number.yaml
their stepping is 0.1 :slight_smile:

the High slider has this bug, where the values ending with .2 .4 and .7 get values like
1.2000000000000002, etc…

#high comfort for climate control
comfortctrl_high:
name: Comfort High
initial: 1.5
min: 1.1
max: 1.8
step: 0.1

the Low slider, defined below, behaves correctly:

#Low comfort for climate control
comfortctrl_low:
name: Comfort Low
initial: 0.9
min: 0
max: 1
step: 0.1

I saw there was a similar issue in the angular material github but it was fixed
By mistake i posted there first, in fact reporting that issue is still not resolved (!!!) - will edit my post in angular issue tracking, to reflect this confusion.

But, i assume that home assistant is using angular material for these controls. Any idea how to check what is the used version?

thanks,
-a

This is just the nature of floats in Python. E.g., at a Python prompt I did this:

>>> x = 1.5
>>> x = x - 0.1
>>> x
1.4
>>> x = x - 0.1
>>> x
1.2999999999999998

Same thing in jinja:

{% set x = 1.5 %}
{% set x = x - 0.1 %}
{{ x }}
{%- set x = x - 0.1 %}
{{ x }}

gets:

1.4
1.2999999999999998

If you want it rounded to some precision, you can do that when you need to using the round filter. E.g., adding this to the above:

{{ x|round(2) }}

gets:

1.3

thanks @pnbruckner

your explanation is most probably the root cause, but i think the ui control (slider) should be fixed to display a rounded value - e.g. to the same decimal number as used by the step… (in my case, 1).

visually it’s hurting :slight_smile: for example, take a look at these 2 screenshots; it’s same control, changing from 1.3 to 1.2…

ui_slider_bug

Agreeeeeed (Post has to be at least 10 characters. Argh! :slight_smile:)