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

Add float function to parse string to floating point value #3307

Closed
jpap opened this issue Apr 9, 2017 · 4 comments · Fixed by #3921
Closed

Add float function to parse string to floating point value #3307

jpap opened this issue Apr 9, 2017 · 4 comments · Fixed by #3921

Comments

@jpap
Copy link

jpap commented Apr 9, 2017

Please add a float function so that we can convert a string into a floating point number, analogous to the int function for integers.

This will allow us to pass named floating point arguments from a shortcode.

For my use-case, this is to pass a non-integer "aspect ratio" value. My current workaround is to supply this as a rational two-integer tuple and to perform the division in the template, but is only an approximation when the value is irrational.

@mimattr
Copy link

mimattr commented Sep 7, 2017

Agreed, the addition of a float function would be very useful and also allow a single string (frontmatter) to contain multiple float values using a separator for later expansion/manipulation (template).

Is something similar already on the roadmap?

Many thanks in advance.

@bep bep added the Enhancement label Sep 7, 2017
@bep bep added this to the v0.28 milestone Sep 7, 2017
@bep bep modified the milestones: v0.28, v0.29 Sep 21, 2017
@bep bep modified the milestones: v0.29, v0.30 Sep 26, 2017
@x3ro
Copy link
Contributor

x3ro commented Sep 27, 2017

Hi from a Hacktoberfestler 👋 I'd like to give implementing this a try!

@bep
Copy link
Member

bep commented Sep 27, 2017

@x3ro great; it should live in the tpl/cast package; see ToInt for inspiration.

/cc @moorereason

x3ro added a commit to x3ro/hugo that referenced this issue Sep 27, 2017
Add a template function that allows conversion to float. This is
useful, for example, when passing aspect ratios into templates,
which tend to not be integers.

Fixes gohugoio#3307
x3ro added a commit to x3ro/hugo that referenced this issue Sep 27, 2017
Add a template function that allows conversion to float. This is
useful, for example, when passing aspect ratios into templates,
which tend to not be integers.

Fixes gohugoio#3307
x3ro added a commit to x3ro/hugo that referenced this issue Sep 28, 2017
Add a template function that allows conversion to float. This is
useful, for example, when passing aspect ratios into templates,
which tend to not be integers.

Fixes gohugoio#3307
x3ro added a commit to x3ro/hugo that referenced this issue Sep 28, 2017
Add a template function that allows conversion to float. This is
useful, for example, when passing aspect ratios into templates,
which tend to not be integers.

Fixes gohugoio#3307
@bep bep closed this as completed in #3921 Sep 28, 2017
bep pushed a commit that referenced this issue Sep 28, 2017
Add a template function that allows conversion to float. This is
useful, for example, when passing aspect ratios into templates,
which tend to not be integers.

Fixes #3307
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants