{"record":{"id":"839a1e3b2228f946","repo":"gohugoio/hugo","slug":"invalid-precision-d","errorCode":null,"errorMessage":"invalid precision: %d","messagePattern":"invalid precision: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/lang/lang.go","lineNumber":115,"sourceCode":"//\n// The return value is formatted with at least two decimal places.\nfunc (ns *Namespace) FormatAccounting(precision, currency, number any) (string, error) {\n\tp, n, err := ns.castPrecisionNumber(precision, number)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\treturn ns.translator.FormatAccounting(n, p, cast.ToString(currency)), nil\n}\n\nfunc (ns *Namespace) castPrecisionNumber(precision, number any) (int, float64, error) {\n\tp, err := cast.ToIntE(precision)\n\tif err != nil {\n\t\treturn 0, 0, err\n\t}\n\n\t// Sanity check.\n\tif p > 20 {\n\t\treturn 0, 0, fmt.Errorf(\"invalid precision: %d\", precision)\n\t}\n\n\tn, err := cast.ToFloat64E(number)\n\tif err != nil {\n\t\treturn 0, 0, err\n\t}\n\treturn p, n, nil\n}\n\n// FormatNumberCustom formats a number with the given precision. The first\n// options parameter is a space-delimited string of characters to represent\n// negativity, the decimal point, and grouping. The default value is `- . ,`.\n// The second options parameter defines an alternate delimiting character.\n//\n// Note that numbers are rounded up at 5 or greater.\n// So, with precision set to 0, 1.5 becomes `2`, and 1.4 becomes `1`.\n//\n// For a simpler function that adapts to the current language, see FormatNumber.","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/lang/lang.go#L97-L133","documentation":"FormatNumber, FormatPercent, FormatCurrency, and FormatAccounting share castPrecisionNumber, which caps precision at 20 digits as a sanity guard. Any precision value above 20 is rejected. See lang.go:113-116.","triggerScenarios":"{{ lang.FormatNumber 25 3.14159 }} passing a precision greater than 20.","commonSituations":"Precision sourced from front matter or config without bounds checking; off-by-one or unit confusion (e.g. treating basis points as decimal places).","solutions":["Lower precision to 20 or fewer decimal places.","Clamp the precision value from config/front matter before passing it.","Reconsider whether such high precision is meaningful for the output."],"exampleFix":"// before\n{{ lang.FormatNumber 25 .Value }}\n\n// after\n{{ lang.FormatNumber 20 .Value }}","handlingStrategy":"validation","validationCode":"// Clamp precision to the supported maximum before formatting.\nif p > 20 { p = 20 }\n// or reject:\nif p > 20 { return \"\", fmt.Errorf(\"precision %d exceeds max 20\", p) }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp precision values coming from config or front matter.","Double-check units (basis points vs decimal places) when computing precision."],"tags":["hugo","lang","formatting","numeric","validation"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}