Using the round() filter and its not working for me

I really really don’t understand whats happening here.

I’ve setup an example calculation, and shown the two values I am calculating. Every search I have made to try and fix this all say that all you need to do is add’ | round(1)’. So what am I doing wrong here… Why are two floating numbers with the correct amount of decimal places resulting in a number with many, and after I have added ‘| round(1)’

In the example above all I want is the calculation to say 4.7, not 4.699999999999999
I am going to assume there is some basic thing I am not getting, adding or overlooking.

Can anyone please help me.

1 Like

Yup, Im was sure this question has been asked many times before.

I checked out the link below and the final reply by @petro (a moderator) gave two solutions to ‘fix’ it.
1 Round the value – I thought that is what I was doing, so that post isn’t exactly relevant to my problem. or
2. Format it – I assume that means by adding ‘{:.1f}’.format(states…

I really don’t mean to be annoyingly pedantic, It’s just that the OP on the thread you linked was trying to modify the float not the round, which is what I was trying to do. @petro’s first fix suggestion is what I have been trying.

I think putting the substraction into parenthesis will do the trick:
{{ (measuring.test - states(‘input_number.autoac_changer’)) | round(1)}}

1 Like
{{ (measuring.test - states('input_number.autoac_changer') | float(0)) | round(1) }}
2 Likes

Thank you everyone. The last two suggestions were the fixes I needed, and to @finity, I now understand why its happening! Cheers.

3 Likes