Skip to main content
The number field stores numeric (float64) values and supports min/max validation, integer-only constraints, and special arithmetic setter modifiers for incrementing and decrementing values.

Configuration options

min
*float64
Minimum allowed field value. Set to nil to skip the validator.
max
*float64
Maximum allowed field value. Set to nil to skip the validator.
onlyInt
bool
default:"false"
When true, requires the field value to be an integer (no decimal numbers).
required
bool
default:"false"
When true, requires the field value to be non-zero.

Validation rules

The number field validates:
  • Type: Value must be a valid float64 (not NaN or Infinity)
  • Min/Max: If specified, value must be within the range
  • Integer only: If enabled, value must not have decimal places
  • Required: If enabled, value cannot be zero

Special setter modifiers

The number field supports arithmetic modifiers for incrementing and decrementing values:
// Add to the current value
record.Set("total+", 5)
// If total was 10, it becomes 15

record.Set("count+", 1)
// Increment by 1
The + and - modifiers are useful for atomic updates like incrementing counters or adjusting balances without needing to retrieve the current value first.

Go examples

import "github.com/pocketbase/pocketbase/core"

field := &core.NumberField{
    Name:     "age",
    Required: true,
    OnlyInt:  true,
}

collection.Fields.Add(field)

// Set field value
record.Set("age", 25)

Database column type

NUMERIC DEFAULT 0 NOT NULL

Best practices

  • Use onlyInt for values that should never have decimals (counts, IDs, etc.)
  • Set appropriate min and max constraints to prevent invalid data
  • Use the + and - modifiers for counters to avoid race conditions
  • For monetary values, consider storing as integers (cents) to avoid floating-point precision issues

Zero value

The zero value for number fields is 0.