nats-io/nats-server · error
expected float, but got '%s'
Error message
expected float, but got '%s'
What it means
An item classified as itemFloat could not be parsed by strconv.ParseFloat at all — the error was not ErrRange, so the literal is not a valid float syntax. The parser reports the offending text verbatim.
Source
Thrown at conf/parse.go:356
case "tb", "ti", "tib":
setValue(it, num*1024*1024*1024*1024)
case "p":
setValue(it, num*1000*1000*1000*1000*1000)
case "pb", "pi", "pib":
setValue(it, num*1024*1024*1024*1024*1024)
case "e":
setValue(it, num*1000*1000*1000*1000*1000*1000)
case "eb", "ei", "eib":
setValue(it, num*1024*1024*1024*1024*1024*1024)
}
case itemFloat:
num, err := strconv.ParseFloat(it.val, 64)
if err != nil {
if e, ok := err.(*strconv.NumError); ok &&
e.Err == strconv.ErrRange {
return fmt.Errorf("float '%s' is out of the range", it.val)
}
return fmt.Errorf("expected float, but got '%s'", it.val)
}
setValue(it, num)
case itemBool:
switch strings.ToLower(it.val) {
case "true", "yes", "on":
setValue(it, true)
case "false", "no", "off":
setValue(it, false)
default:
return fmt.Errorf("expected boolean value, but got '%s'", it.val)
}
case itemDatetime:
dt, err := time.Parse("2006-01-02T15:04:05Z", it.val)
if err != nil {
return fmt.Errorf(
"expected Zulu formatted DateTime, but got '%s'", it.val)
}View on GitHub (pinned to 3a66a489d2)
Solutions
- Correct the value to valid Go float syntax: digits with optional '.', sign, exponent (e.g. 3.14, 1e5).
- Replace decimal commas with dots.
- Remove units/symbols from the value; express units via the key name or a separate field.
- Quote the value as a string and parse it in application code if non-standard syntax is required.
Example fix
// before threshold = 3,14% // after threshold = 3.14
Defensive patterns
Strategy: validation
Validate before calling
if _, err := strconv.ParseFloat(raw, 64); err != nil {
return fmt.Errorf("%q is not a valid float: %w", raw, err)
} Prevention
- Use dots, not commas, for decimal separators.
- Keep units and symbols out of numeric config values.
- Validate config values with strconv.ParseFloat in CI before deployment.
When it happens
Trigger: processItem (from parse) reaches case itemFloat with it.val like '1,5', '1_000', '0x1f' in an unquoted context, '3.14.15', or empty text lexed as a float.
Common situations: Locale-formatted decimal commas, thousand separators, trailing units ('100ms', '5%'), typo'd strings where a number was expected, or a lexer misclassification.
Related errors
- float '%s' is out of the range
- config is invalid (%s:%d:%d)
- Parse error on line %d: '%s'
- expected boolean value, but got '%s'
- expected Zulu formatted DateTime, but got '%s'
AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02).
Data as JSON: /api/errors/6e004beaba9732ce.
Report an issue: GitHub.