{"id":"0e1c496d786f15f8","repo":"gohugoio/hugo","slug":"too-many-fields-in-options-parameter-to-numfmt","errorCode":null,"errorMessage":"too many fields in options parameter to NumFmt","messagePattern":"too many fields in options parameter to NumFmt","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/lang/lang.go","lineNumber":178,"sourceCode":"\t\t\tdelim = s\n\t\t}\n\n\t\ts, err := cast.ToStringE(options[0])\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\n\t\trs := strings.Split(s, delim)\n\t\tswitch len(rs) {\n\t\tcase 0:\n\t\tcase 1:\n\t\t\tneg = rs[0]\n\t\tcase 2:\n\t\t\tneg, dec = rs[0], rs[1]\n\t\tcase 3:\n\t\t\tneg, dec, grp = rs[0], rs[1], rs[2]\n\t\tdefault:\n\t\t\treturn \"\", errors.New(\"too many fields in options parameter to NumFmt\")\n\t\t}\n\t}\n\n\texp := math.Pow(10.0, float64(prec))\n\tr := math.Round(n*exp) / exp\n\n\t// Logic from MIT Licensed github.com/gohugoio/locales/\n\t// Original Copyright (c) 2016 Go Playground\n\n\ts := strconv.FormatFloat(math.Abs(r), 'f', prec, 64)\n\tL := len(s) + 2 + len(s[:len(s)-1-prec])/3\n\n\tvar count int\n\tinWhole := prec == 0\n\tb := make([]byte, 0, L)\n\n\tfor i := len(s) - 1; i >= 0; i-- {\n\t\tif s[i] == '.' {","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/lang/lang.go#L160-L196","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"<!-- before -->\n{{ lang.FormatNumberCustom 2 12345.6789 \"- . , extra\" }}\n<!-- after -->\n{{ lang.FormatNumberCustom 2 12345.6789 \"- . ,\" }}","handlingStrategy":"validation","validationCode":"{{ $opts := \"- . ,\" }}\n{{ if le (len (split $opts \" \")) 4 }}{{ lang.NumFmt 2 1234.56 $opts }}{{ end }}","typeGuard":null,"tryCatchPattern":"{{ with try (lang.NumFmt 2 1234.56 $opts) }}{{ with .Err }}{{ warnf \"NumFmt options invalid: %s\" . }}{{ else }}{{ .Value }}{{ end }}{{ end }}","preventionTips":["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"],"tags":["hugo","templates","number-formatting"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}