{"id":"a449182c6cda46d5","repo":"gohugoio/hugo","slug":"ceil-operator-can-t-be-used-with-non-float-value","errorCode":null,"errorMessage":"Ceil operator can't be used with non-float value","messagePattern":"Ceil operator can't be used with non-float value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/math/math.go","lineNumber":105,"sourceCode":"\n// Atan2 returns the arc tangent of n/m, using the signs of the two to determine the quadrant of the return value.\nfunc (ns *Namespace) Atan2(n, m any) (float64, error) {\n\tafx, err := cast.ToFloat64E(n)\n\tif err != nil {\n\t\treturn 0, errors.New(\"requires numeric arguments\")\n\t}\n\tafy, err := cast.ToFloat64E(m)\n\tif err != nil {\n\t\treturn 0, errors.New(\"requires numeric arguments\")\n\t}\n\treturn math.Atan2(afx, afy), nil\n}\n\n// Ceil returns the least integer value greater than or equal to n.\nfunc (ns *Namespace) Ceil(n any) (float64, error) {\n\txf, err := cast.ToFloat64E(n)\n\tif err != nil {\n\t\treturn 0, errors.New(\"Ceil operator can't be used with non-float value\")\n\t}\n\n\treturn math.Ceil(xf), nil\n}\n\n// 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}","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/math/math.go#L87-L123","documentation":"math.Ceil converts its argument to float64 via cast.ToFloat64E and returns this error when the conversion fails. Despite the wording ('non-float'), any castable numeric — int, float, or numeric string — is accepted; the error means the input was not numeric at all.","triggerScenarios":"`{{ math.Ceil \"2.x\" }}`, `{{ math.Ceil .Params.ratio }}` where the param is nil, a non-numeric string, a slice, or a map.","commonSituations":"Pagination or grid math (`math.Ceil (div (len .Pages) 3)`) where an upstream value is a string from front matter; missing params resolving to nil; locale-formatted numbers with commas (\"1,5\") that cast rejects.","solutions":["Ensure the argument is numeric: `{{ math.Ceil 2.4 }}`.","Convert explicitly first: `{{ math.Ceil (float $v) }}` or supply `| default 0` for possibly-missing params.","Normalize locale strings (replace comma with dot) before converting."],"exampleFix":"<!-- before -->\n{{ math.Ceil .Params.ratio }}  {{/* ratio: \"1,5\" */}}\n<!-- after -->\n{{ math.Ceil (float (replace .Params.ratio \",\" \".\")) }}","handlingStrategy":"type-guard","validationCode":"{{ $v := .Params.price }}\n{{ math.Ceil (float $v) }}","typeGuard":"{{ with try (float $v) }}{{ if not .Err }}{{ math.Ceil .Value }}{{ end }}{{ end }}","tryCatchPattern":"{{ with try (math.Ceil $v) }}{{ if .Err }}{{ warnf \"Ceil needs a float: %s\" .Err }}{{ else }}{{ .Value }}{{ end }}{{ end }}","preventionTips":["math.Ceil requires a value castable to float64 — pipe through `float` first when the source is a string or interface","Front-matter numbers written as strings are the common trigger","Validate data-file values once at the top of the template, not at each use site"],"tags":["hugo","templates","math","type-conversion","ceil"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}