> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/pocketbase/pocketbase/llms.txt
> Use this file to discover all available pages before exploring further.

# Number field

> Store numeric values with optional min/max constraints and arithmetic modifiers

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

<ParamField path="min" type="*float64">
  Minimum allowed field value. Set to nil to skip the validator.
</ParamField>

<ParamField path="max" type="*float64">
  Maximum allowed field value. Set to nil to skip the validator.
</ParamField>

<ParamField path="onlyInt" type="bool" default="false">
  When true, requires the field value to be an integer (no decimal numbers).
</ParamField>

<ParamField path="required" type="bool" default="false">
  When true, requires the field value to be non-zero.
</ParamField>

## 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:

<CodeGroup>
  ```go Increment theme={null}
  // Add to the current value
  record.Set("total+", 5)
  // If total was 10, it becomes 15

  record.Set("count+", 1)
  // Increment by 1
  ```

  ```go Decrement theme={null}
  // Subtract from the current value
  record.Set("total-", 3)
  // If total was 15, it becomes 12

  record.Set("count-", 1)
  // Decrement by 1
  ```
</CodeGroup>

<Info>
  The `+` and `-` modifiers are useful for atomic updates like incrementing counters or adjusting balances without needing to retrieve the current value first.
</Info>

## Go examples

<Tabs>
  <Tab title="Basic usage">
    ```go theme={null}
    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)
    ```
  </Tab>

  <Tab title="With min/max constraints">
    ```go theme={null}
    min := 0.0
    max := 100.0

    field := &core.NumberField{
        Name:    "percentage",
        Min:     &min,
        Max:     &max,
        OnlyInt: false,
    }

    collection.Fields.Add(field)

    record.Set("percentage", 75.5)
    ```
  </Tab>

  <Tab title="Counter with modifiers">
    ```go theme={null}
    field := &core.NumberField{
        Name:    "views",
        OnlyInt: true,
    }

    collection.Fields.Add(field)

    // Increment views counter
    record.Set("views+", 1)

    // Decrement if needed
    record.Set("views-", 1)
    ```
  </Tab>

  <Tab title="Price field">
    ```go theme={null}
    min := 0.0

    field := &core.NumberField{
        Name:     "price",
        Required: true,
        Min:      &min,
    }

    collection.Fields.Add(field)

    record.Set("price", 29.99)
    ```
  </Tab>
</Tabs>

## Database column type

```sql theme={null}
NUMERIC DEFAULT 0 NOT NULL
```

## Best practices

<Note>
  * 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
</Note>

## Zero value

The zero value for number fields is `0`.
