{"record":{"id":"173f2e785cef5b1b","repo":"gohugoio/hugo","slug":"floor-operator-can-t-be-used-with-non-float-value","errorCode":null,"errorMessage":"Floor operator can't be used with non-float value","messagePattern":"Floor operator can't be used with non-float value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/math/math.go","lineNumber":129,"sourceCode":"// Cos returns the cosine of the radian argument n.\nfunc (ns *Namespace) Cos(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.Cos(af), nil\n}\n\n// Div divides n1 by n2.\nfunc (ns *Namespace) Div(inputs ...any) (any, error) {\n\treturn ns.doArithmetic(inputs, '/')\n}\n\n// Floor returns the greatest integer value less than or equal to n.\nfunc (ns *Namespace) Floor(n any) (float64, error) {\n\txf, err := cast.ToFloat64E(n)\n\tif err != nil {\n\t\treturn 0, errors.New(\"Floor operator can't be used with non-float value\")\n\t}\n\n\treturn math.Floor(xf), nil\n}\n\n// Log returns the natural logarithm of the number n.\nfunc (ns *Namespace) Log(n any) (float64, error) {\n\taf, err := cast.ToFloat64E(n)\n\tif err != nil {\n\t\treturn 0, errors.New(\"Log operator can't be used with non integer or float value\")\n\t}\n\n\treturn math.Log(af), nil\n}\n\n// Max returns the greater of all numbers in inputs. Any slices in inputs are flattened.\nfunc (ns *Namespace) Max(inputs ...any) (maximum float64, err error) {\n\treturn ns.applyOpToScalarsOrSlices(\"Max\", math.Max, inputs...)","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/math/math.go#L111-L147","documentation":"Thrown by math.Floor (tpl/math/math.go:129) when its argument cannot be converted to float64. Floor returns the greatest integer <= n and needs a float-convertible input.","triggerScenarios":"Calling {{ math.Floor .Value }} with a non-numeric string, nil, bool, struct, or slice.","commonSituations":"Unset param (nil); text field where a number was expected; quoted numeric string that fails conversion.","solutions":["Pass a numeric value to math.Floor.","Add a numeric default: {{ math.Floor (.Param \"n\" | default 0) }}.","Guard behind a numeric check on the source value.","Fix the source data so the field is numeric."],"exampleFix":"// before\n{{ math.Floor .Params.score }}\n\n// after\n{{ $n := .Params.score | default 0 }}\n{{ math.Floor $n }}","handlingStrategy":"type-guard","validationCode":"// Validate numeric input before math.Floor:\n{{ $v := .Param \"n\" | default 0 }}\n{{ math.Floor $v }}","typeGuard":"// Reuse the isNumeric guard from errorIndex 148 before calling math.Floor.","tryCatchPattern":null,"preventionTips":["Pass numeric values to math.Floor.","Default unset params to a number.","Keep source numeric fields unquoted."],"tags":["hugo","template","math","type-validation","rounding"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}