> For the complete documentation index, see [llms.txt](https://codemash.gitbook.io/codemash/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://codemash.gitbook.io/codemash/cloud/database/schema/field-types/decimal.md).

# Decimal

A decimal number field with minimum, maximum and a fixed number of decimal places (multipleOf).

A **Decimal** field stores a number with a fraction — a weight, a score, a percentage. `multipleOf` fixes how many decimal places are allowed.

**Builder:** Form fields panel → **Number (decimal places)** · widget `number` · data type `decimal.schema.v1`

## Data schema

```json
{
  "weight": {
    "type": "number",
    "minimum": 0,
    "maximum": 1000,
    "multipleOf": 0.01,
    "default": 1.5
  }
}
```

| Keyword               | Required | What it does                                                                                  | Example      |
| --------------------- | -------- | --------------------------------------------------------------------------------------------- | ------------ |
| `type`                | yes      | Always `"number"`.                                                                            | `"number"`   |
| `minimum` / `maximum` | no       | The allowed range.                                                                            | `0` / `1000` |
| `multipleOf`          | no       | The step: one of `0.1`, `0.01`, `0.001`, `0.0001`, `0.00001` — that is 1 to 5 decimal places. | `0.01`       |
| `default`             | no       | The value a new record gets when the field is left out.                                       | `1.5`        |
| `unique`              | no       | `true` = no two records share the value.                                                      | `true`       |

### What the server refuses

Every write — insert, update, replace; from Cloud, the API, an SDK, the CLI or an AI agent — is checked against the published schema. A broken value is answered with one error per field: the code, and `Field '<name>' is invalid: <reason>`. Nothing is written.

| Case                                         | Code                     | The reason it gives                           |
| -------------------------------------------- | ------------------------ | --------------------------------------------- |
| a required field is missing or `null`        | `CM-ERRORS-DATABASE-030` | `a value is required`                         |
| not a number                                 | `CM-ERRORS-DATABASE-039` | `must be a number`                            |
| below `minimum` / above `maximum`            | `CM-ERRORS-DATABASE-043` | `must be at least 0` / `must be at most 1000` |
| more decimal places than `multipleOf` allows | `CM-ERRORS-DATABASE-044` | `must be a multiple of 0.01`                  |

A keyword that is not in the table above is refused when the schema is **saved**, not when a record is written: `CM-ERRORS-SCHEMA-010` — `Data schema violates meta-schema: Property 'sort' has not been defined and the schema does not allow additional properties. Path 'properties.weight.sort' (field 'properties.weight' checked as decimal.schema.v1).`

Also refused at save time:

* a `multipleOf` that is not one of the five steps — `CM-ERRORS-SCHEMA-010` (the meta-schema lists the allowed values).
* a `default` off the step or outside the range — `CM-ERRORS-SCHEMA-037`.

## UI schema

The cell uses the `number` widget; the step is a data rule, so it is not repeated in the UI schema.

```json
{
  "colSpan": 4,
  "element": {
    "fieldId": "weight",
    "meta": { "widget": "number", "label": "Weight (kg)" }
  }
}
```

Every cell also takes the common layout options: `label`, `placeholder`, `help` (the text under the input), `required`, `readonly` and `hidden`. Keys outside this list — `watermark`, `hint`, `permissions` — are refused when the schema is saved (`CM-ERRORS-SCHEMA-012`), see [Schema authoring guide](/codemash/cloud/database/schema.md#one-contract-no-second-dialect).

<figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-6319b8c01b4c7c41c3221641516b145e6b57df60%2Ffield-types-numbers-1.png?alt=media" alt="The Numbers tab of the all-types record form: Decimal plain, Decimal type, Decimal minimum, Decimal maximum, Decimal step and Decimal default as number inputs"><figcaption><p>Decimal cells on the Numbers tab.</p></figcaption></figure>

## Records

A record the schema accepts:

```json
{ "weight": 12.25 }
```

A record it refuses:

```json
{ "weight": 12.255 }
```

The answer: `CM-ERRORS-DATABASE-044` — `Field 'weight' is invalid: must be a multiple of 0.01`. In Cloud the same sentence is shown under the field before the form is sent; the server repeats the check on every API write.

## Good to know

* For money use a [Currency](/codemash/cloud/database/schema/field-types/currency.md) field: it keeps the amount and the currency code together and has the same `multipleOf` step for the amount.
* Values are stored as doubles; keep `multipleOf` to the places you need.

## Do it from code

```ts
await norbix.api.database.insertOne({
  collectionName: 'products',
  document: JSON.stringify({ weight: 12.25 }),
});
```

```sh
norbix api database one insert --collectionName products --document '{"weight":12.25}'
```

The client setup is on the [Database page](/codemash/cloud/database.md#use-it-from-code). API: [Insert One](/codemash/api-reference/database/collections/insert-one.md) · [Save Database Schema](/codemash/api-reference/database/schemas/save-database-schema.md)

## Related

[Integer](/codemash/cloud/database/schema/field-types/integer.md) · [Currency](/codemash/cloud/database/schema/field-types/currency.md) · [Field type reference](/codemash/cloud/database/schema/field-types.md) · [Schema authoring guide](/codemash/cloud/database/schema.md) · [Create a schema](/codemash/cloud/database/collections/create-schema.md)
