Configuration options
Minimum allowed field value. Set to nil to skip the validator.
Maximum allowed field value. Set to nil to skip the validator.
When true, requires the field value to be an integer (no decimal numbers).
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:The
+ and - modifiers are useful for atomic updates like incrementing counters or adjusting balances without needing to retrieve the current value first.Go examples
- Basic usage
- With min/max constraints
- Counter with modifiers
- Price field
Database column type
Best practices
- Use
onlyIntfor values that should never have decimals (counts, IDs, etc.) - Set appropriate
minandmaxconstraints 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 is0.