Format numbers in a specific fashion

Let’s say I have numbers in front matter formatted as “01.010” and “01.0105”

I want it to appear on the website the same way.

  1. Minimum of 3 decimal places but more if they are there and
  2. Always two digits on the whole number side with a leading zero.
{{ with .Params.foo }}
  {{ $precision := math.Max 3 (sub (len (path.Ext .)) 1) | int }}
  {{ $width := add 3 $precision | int }}
  {{ printf "%0*.*f" $width $precision (float .) }}
{{ end }}
2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.