i was annoyed by a RESTful sensor giving me strange readings. First idea was something might be wrong with the data. But it looked okay. The returned value was “0.554” and the template was quite simple:
value_template: "{{ quote * 100 | round(2) }}"
So my expectation would be the output to be “55.40%”. But instead i got this:
Python standard float variable type is double precision by default. But if I linked float explanation (that has the same deficiencies and positives but less precision) it would not line up with what OP is seeing.
Yeah, all languages that use floating point do. It’s the nature of floating point. Some math libraries round for you but rounding floating point to desired precision for displaying is a normal thing that we all probably do automatically and don’t even think about it.
Base 12 is not the same as a double/float. double/floats, any other floating point number are all base 10, they just have more precision. The higher the bits, the higher the precision with a trade off of using more memory.
The good think is that printf rounds the result, and the comparison is correct, so it’s transparent.
And thanks for the round() link, the default “round-to-even” was my main surprise, I will use the downward/ceil one, which is more coherent with C math lib: