# Round() function no longer rounding

I have a template sensor:

``````    # reads 1 hPa high compared to local stations
- platform: template
sensors:
outside_pressure_msl:
friendly_name: "Outside Air Pressure MSL"
unit_of_measurement: hPa
value_template: "{{ ((states('sensor.outside_air_pressure')|float * (1 - (0.0065 * 175) / (states('sensor.outside_temperature')|float + (0.0065 * 175) + 273.15)) ** -5.257) | round(1)) - 1  }}"
icon_template: mdi:gauge
``````

This used to work fine, after the latest update however I get this result:

Has templating changed? This used to work, nothing has changed in the template. Can anyone spot an error that was “fixed” in the latest update?

See Phil’s post, here: How to round the result of adjusted temperature

1 Like

Ah - I see. The gist of it is that round is a mathematical function, not a formatting function. Thanks for this.

I had two pi’s up and runing, with exact same config (I was migrating from a pi3 to a pi4) one displayed units correctly, the other had an extra 0000002 on the end after the decimal
I then changed to the formatting option from Phil and everything is okay.
Apparently (for some unfathomable reason) this is not considered a bug and resides in the python code base and has nothing to do with HA

I’m not sure how you’d submit a pull request to the maintainers of python

Though you can (say) to get 2 dp you can always multiply by 100, int, then divide by 100 as int is a trusty stalwart

It’s not unfathomable nor a bug. It’s the nature of floating point math where representations of values have a finite resolution, and especially where the representation is binary and not decimal. See for example: decimal — Decimal fixed point and floating point arithmetic — Python 3.8.18 documentation

1 Like

Yes Phil, We have had this discussion previously, I was just putting it for the ‘average HA user’ to put in context, not blame HA and give a workaround (as I have to check my previous efforts to get the formatting right, whereas the " * 100) | int / 100" is easy to remember. But obviously uses more operations.