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 · 3 comments

Comments

Projects
None yet
4 participants
@jpap

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

This comment has been minimized.

Show comment
Hide comment
@mimattr

mimattr 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.

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 added the Hacktoberfest label Sep 22, 2017

@bep bep modified the milestones: v0.29, v0.30 Sep 26, 2017

@x3ro

This comment has been minimized.

Show comment
Hide comment
@x3ro

x3ro Sep 27, 2017

Contributor

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

Contributor

x3ro commented Sep 27, 2017

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

@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Sep 27, 2017

Member

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

/cc @moorereason

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

tpl: Add float template function
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

tpl: Add float template function
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

tpl: Add float template function
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

tpl: Add float template function
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 in #3921 Sep 28, 2017

bep added a commit that referenced this issue Sep 28, 2017

tpl: Add float template function
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment