Hi there,
How can I get 5.0 instead of 5 value in Hugo?
# current setup
{{ .rating }} = 5
# preferred setup
{{ .rating | numFormat something here }} = 5.0
Thanks
Hi there,
How can I get 5.0 instead of 5 value in Hugo?
# current setup
{{ .rating }} = 5
# preferred setup
{{ .rating | numFormat something here }} = 5.0
Thanks
{{ printf â%.1fâ (float .rating) }}
To clarify, you can do either of these:
{{ 5 | lang.FormatNumber 1 }}
{{ 5 | float | printf "%.1f" }}
The first one localizes the value (i.e., period vs. comma depending on locale), but the second is a little bit faster.
Note that the cast.ToFloat
function takes only 1 argument.
thx to @jmooring for
float
removed that from original post - dunno where I got that from