{"record":{"id":"3bed0b9c9eb84709","repo":"gohugoio/hugo","slug":"round-operator-can-t-be-used-with-non-float-value","errorCode":null,"errorMessage":"Round operator can't be used with non-float value","messagePattern":"Round operator can't be used with non-float value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/math/math.go","lineNumber":225,"sourceCode":"\n// Product returns the product of all numbers in inputs. Any slices in inputs are flattened.\nfunc (ns *Namespace) Product(inputs ...any) (product float64, err error) {\n\tfn := func(x, y float64) float64 {\n\t\treturn x * y\n\t}\n\treturn ns.applyOpToScalarsOrSlices(\"Product\", fn, inputs...)\n}\n\n// Rand returns, as a float64, a pseudo-random number in the half-open interval [0.0,1.0).\nfunc (ns *Namespace) Rand() float64 {\n\treturn rand.Float64()\n}\n\n// Round returns the integer nearest to n, rounding half away from zero.\nfunc (ns *Namespace) Round(n any) (float64, error) {\n\txf, err := cast.ToFloat64E(n)\n\tif err != nil {\n\t\treturn 0, errors.New(\"Round operator can't be used with non-float value\")\n\t}\n\n\treturn _round(xf), nil\n}\n\n// Sin returns the sine of the radian argument n.\nfunc (ns *Namespace) Sin(n any) (float64, error) {\n\taf, err := cast.ToFloat64E(n)\n\tif err != nil {\n\t\treturn 0, errors.New(\"requires a numeric argument\")\n\t}\n\treturn math.Sin(af), nil\n}\n\n// Sqrt returns the square root of the number n.\nfunc (ns *Namespace) Sqrt(n any) (float64, error) {\n\taf, err := cast.ToFloat64E(n)\n\tif err != nil {","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/math/math.go#L207-L243","documentation":"Thrown by math.Round when its single argument cannot be converted to float64 by cast.ToFloat64E. Round rounds half away from zero and needs a numeric input; booleans, nil, structs, slices, and non-numeric strings all fail conversion.","triggerScenarios":"Calling {{ math.Round \"foo\" }}, {{ math.Round $nilVar }}, or {{ math.Round .Params.someUndefinedKey }}. Also when a front matter field is a date or duration object rather than a number.","commonSituations":"Rounding a value pulled from params that was authored as a string; passing a time.Time or resource object by mistake; conditional sections where the value is unset on some pages.","solutions":["Cast or default the input: {{ math.Round (float ($v | default 0)) }}.","Guard with an if block: {{ if $v }}{{ math.Round $v }}{{ end }}.","Fix front matter to use numeric types instead of quoted strings."],"exampleFix":"// before\n{{ math.Round .Params.rating }}\n// after\n{{ with .Params.rating }}{{ math.Round . }}{{ end }}","handlingStrategy":"validation","validationCode":"{{ with $v }}{{ math.Round (float .) }}{{ end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Wrap math.Round in an {{ with }} block to skip nil values.","Cast with (float ...) when the source is a string param.","Use numeric front matter types."],"tags":["template","math","type-conversion","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}