Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue while converting to float #966

Closed
ghost opened this issue Apr 2, 2019 · 1 comment
Closed

Issue while converting to float #966

ghost opened this issue Apr 2, 2019 · 1 comment

Comments

@ghost
Copy link

ghost commented Apr 2, 2019

Hey guys,

I came over from the home-assistant community to report an issue we found.

We are trying to convert a comma seperated decimal (as string) to float.

additional info: in germany we always use the comma as seperator

Expected Behavior

the result should be 43.0

Actual Behavior

the result is 0.0

Template Code

{% set x = "43,0" %}
{{x | float}}

Full Traceback

Here is the full discussion instead:
DISCUSSION


## Your Environment
* Python version: 2.7.13
@davidism
Copy link
Member

davidism commented Apr 2, 2019

In Python, float("43,0") raises an error. In Jinja, |float handles that error by using the default, which defaults to 0.0. If you want different behavior, you'll need to register a different float filter.

float(value, default=0.0)

Convert the value into a floating point number. If the conversion doesn’t work it will return 0.0. You can override this default using the first parameter.

@davidism davidism closed this as completed Apr 2, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant