core: Templates: Round is no longer honored on whole numbers. e.g. 1.0, 2.0, etc.

The problem

Rounding is no longer honored as a result of the new template typing. All whole numbers will be truncated to an int.

ex:

{{ '1.1' | round(1) }} # returns 1.1
{{ '1.0' | round(1) }} # returns 1
{{ '1.1' | float | round(1) }} # returns 1.1
{{ '1.0' | float | round(1) }} # returns 1

After follwing the code in the forgiving_round method, it appears as if the bug is beyond that. I would assume that it’s coming from the new template changes because the values that leave forgiving_round contain the floating point decimals.

Environment

  • Home Assistant Core release with the issue: 0.118
  • Last working Home Assistant Core release (if known): 0.116.4
  • Operating environment (OS/Container/Supervised/Core): NA
  • Integration causing this issue: template
  • Link to integration documentation on our website: NA

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 24 (19 by maintainers)

Most upvoted comments

Yep I know that, just want to be clear: This is not desired from a user perspective. Users want their sensors to display the number of sig figs that they output.

@tdejneka because the template is returning more than 1 value. Only use 1 template with no comment and it will return the values I listed.

image

The template resolver tries to type the entire template. So when you have multiple returned values, it typically types it as a string.