gohugoio/hugo · error
too many fields in options parameter to NumFmt
Error message
too many fields in options parameter to NumFmt
What it means
`lang.FormatNumberCustom` (historically aliased as `NumFmt`) takes an options string that, when split by the delimiter, must yield at most three fields: the negative sign, decimal separator, and grouping separator. If the split produces four or more fields, Hugo cannot map them and returns this error.
Source
Thrown at tpl/lang/lang.go:178
delim = s
}
s, err := cast.ToStringE(options[0])
if err != nil {
return "", err
}
rs := strings.Split(s, delim)
switch len(rs) {
case 0:
case 1:
neg = rs[0]
case 2:
neg, dec = rs[0], rs[1]
case 3:
neg, dec, grp = rs[0], rs[1], rs[2]
default:
return "", errors.New("too many fields in options parameter to NumFmt")
}
}
exp := math.Pow(10.0, float64(prec))
r := math.Round(n*exp) / exp
// Logic from MIT Licensed github.com/gohugoio/locales/
// Original Copyright (c) 2016 Go Playground
s := strconv.FormatFloat(math.Abs(r), 'f', prec, 64)
L := len(s) + 2 + len(s[:len(s)-1-prec])/3
var count int
inWhole := prec == 0
b := make([]byte, 0, L)
for i := len(s) - 1; i >= 0; i-- {
if s[i] == '.' {View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Reduce the options string to exactly three delimiter-separated fields, e.g. "- , ." for European formatting.
- If a separator character conflicts with the space delimiter, pass a custom delimiter as the fourth argument, e.g. `{{ lang.FormatNumberCustom 2 12345.67 "-|.|," "|" }}`.
- Use `lang.FormatNumber` instead if you just want locale-aware formatting for the current language.
Example fix
<!-- before -->
{{ lang.FormatNumberCustom 2 12345.6789 "- . , extra" }}
<!-- after -->
{{ lang.FormatNumberCustom 2 12345.6789 "- . ," }} Defensive patterns
Strategy: validation
Validate before calling
{{ $opts := "- . ," }}
{{ if le (len (split $opts " ")) 4 }}{{ lang.NumFmt 2 1234.56 $opts }}{{ end }} Try / catch
{{ with try (lang.NumFmt 2 1234.56 $opts) }}{{ with .Err }}{{ warnf "NumFmt options invalid: %s" . }}{{ else }}{{ .Value }}{{ end }}{{ end }} Prevention
- The NumFmt options string is space-delimited with at most 4 fields: negative, decimal, grouping, delimiter
- Keep the options string as a literal in the template rather than building it dynamically
- If site params supply the options, validate field count at config time
When it happens
Trigger: Calling `{{ lang.FormatNumberCustom 2 12345.67 "- . , x" }}` — an options string with more than three space-delimited fields; or supplying a custom delimiter as the second option that splits the first option string into 4+ parts.
Common situations: Users trying to pass extra formatting flags in the options string, misunderstanding that only `neg dec grp` are supported; a decimal/grouping character containing the delimiter itself (e.g. a space in the format string) causing an unintended extra split; migrating old NumFmt calls with malformed option strings.
Related errors
- invalid precision: %d
- error building site: %w
- failed to detect format from content
- failed to detect target data serialization format
- templates.Defer cannot be used inside a partialCached partia
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/0e1c496d786f15f8.json.
Report an issue: GitHub ↗.