gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.88k stars 7.54k forks source link

Add feature to humanize function for floats: round them. #7110

Closed jasikpark closed 4 years ago

jasikpark commented 4 years ago

Currently I'm using printf for displaying my image metadata,

{{ with $src.Exif }}
  <ul>
      {{ with .Tags.ApertureValue }}<li>Aperture: {{ (printf "%.2f" .) }}</li>{{ end }}
      {{ with .Tags.BrightnessValue }}<li>Brightness: {{ (printf "%.2f" .) }}</li>{{ end }}
  </ul>
   {{ end }}
{{ with $src.Exif }}
  <ul>
      {{ with .Tags.ApertureValue }}<li>Aperture: {{ (humanize .) }}</li>{{ end }}
      {{ with .Tags.BrightnessValue }}<li>Brightness: {{ (humanize .) }}</li>{{ end }}
  </ul>
   {{ end }}
Jos512 commented 4 years ago

I can see that rounding floats might be a way to 'humanize' text, especially when the value is something like 1.00000000001. And perhaps two decimal digits are a good way to 'standardise' values.

But what about the decimal point? Some countries use a dot, others a comma (overview of those countries). So while 12.34 might be a humanised version of 12.343231 for person A, it might be wrong for person B.

Luckily we already have the lang.NumFmt function for those use cases. And in other cases the math.Round function works well.

jasikpark commented 4 years ago

Ok, cool -- I could not find lang.NumFmt for my life -- maybe something in the documentation adding some keywords about formatting floats could be added so it shows up in search?

github-actions[bot] commented 2 years ago

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.