gohugoio/hugo · error

Ceil operator can't be used with non-float value

Error message

Ceil operator can't be used with non-float value

What it means

Thrown by math.Ceil (tpl/math/math.go:105) when its argument cannot be converted to float64. Ceil returns the least integer >= n and needs a float; cast.ToFloat64E failing produces this Ceil-specific message.

Solutions

  1. Pass a numeric value to math.Ceil.
  2. Add a numeric default: {{ math.Ceil (.Param "n" | default 0) }}.
  3. Guard behind a numeric check on the source value.
  4. Fix the source data so the field is numeric.

Example fix

// before
{{ math.Ceil .Params.count }}

// after
{{ $n := .Params.count | default 0 }}
{{ math.Ceil $n }}
Defensive patterns

Strategy: type-guard

Validate before calling

// Validate numeric input before math.Ceil:
{{ $v := .Param "n" | default 0 }}
{{ math.Ceil $v }}

Type guard

// Reuse the isNumeric guard from errorIndex 148 before calling math.Ceil.

Prevention

When it happens

Trigger: Calling {{ math.Ceil .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


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/a449182c6cda46d5. Report an issue: GitHub.

Appendix: source

Thrown at tpl/math/math.go:105

// Atan2 returns the arc tangent of n/m, using the signs of the two to determine the quadrant of the return value.
func (ns *Namespace) Atan2(n, m any) (float64, error) {
	afx, err := cast.ToFloat64E(n)
	if err != nil {
		return 0, errors.New("requires numeric arguments")
	}
	afy, err := cast.ToFloat64E(m)
	if err != nil {
		return 0, errors.New("requires numeric arguments")
	}
	return math.Atan2(afx, afy), nil
}

// Ceil returns the least integer value greater than or equal to n.
func (ns *Namespace) Ceil(n any) (float64, error) {
	xf, err := cast.ToFloat64E(n)
	if err != nil {
		return 0, errors.New("Ceil operator can't be used with non-float value")
	}

	return math.Ceil(xf), nil
}

// 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, '/')
}

View on GitHub (pinned to 52c9bd7908)