gohugoio/hugo · error
Floor operator can't be used with non-float value
Error message
Floor operator can't be used with non-float value
What it means
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.
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.
Example fix
// before
{{ math.Floor .Params.score }}
// after
{{ $n := .Params.score | default 0 }}
{{ math.Floor $n }} Defensive patterns
Strategy: type-guard
Validate before calling
// Validate numeric input before math.Floor:
{{ $v := .Param "n" | default 0 }}
{{ math.Floor $v }} Type guard
// Reuse the isNumeric guard from errorIndex 148 before calling math.Floor.
Prevention
- Pass numeric values to math.Floor.
- Default unset params to a number.
- Keep source numeric fields unquoted.
When it happens
Trigger: Calling {{ math.Floor .Value }} with a non-numeric string, nil, bool, struct, or slice.
Common situations: Unset param (nil); text field where a number was expected; quoted numeric string that fails conversion.
Related errors
- Ceil operator can't be used with non-float value
- Log operator can't be used with non integer or float value
- modulo operator can't be used with non integer value
- requires a numeric argument
- requires numeric arguments
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/173f2e785cef5b1b.
Report an issue: GitHub.
Appendix: source
Thrown at tpl/math/math.go:129
// Cos returns the cosine of the radian argument n.
func (ns *Namespace) Cos(n any) (float64, error) {
af, err := cast.ToFloat64E(n)
if err != nil {
return 0, errors.New("requires a numeric argument")
}
return math.Cos(af), nil
}
// Div divides n1 by n2.
func (ns *Namespace) Div(inputs ...any) (any, error) {
return ns.doArithmetic(inputs, '/')
}
// Floor returns the greatest integer value less than or equal to n.
func (ns *Namespace) Floor(n any) (float64, error) {
xf, err := cast.ToFloat64E(n)
if err != nil {
return 0, errors.New("Floor operator can't be used with non-float value")
}
return math.Floor(xf), nil
}
// Log returns the natural logarithm of the number n.
func (ns *Namespace) Log(n any) (float64, error) {
af, err := cast.ToFloat64E(n)
if err != nil {
return 0, errors.New("Log operator can't be used with non integer or float value")
}
return math.Log(af), nil
}
// Max returns the greater of all numbers in inputs. Any slices in inputs are flattened.
func (ns *Namespace) Max(inputs ...any) (maximum float64, err error) {
return ns.applyOpToScalarsOrSlices("Max", math.Max, inputs...)View on GitHub (pinned to 52c9bd7908)