# `Rating`

A rating on its own scale: `4.5/5`.

Use it for reviews and scores. It keeps its scale with it, so 4 of 5 and 8 of 10 aren't mixed up. For a plain percentage score, use [`Percentage`](/docs/types/type-percentage.md).

## Shape

| Field | Type | Required? |
|---|---|---|
| `value` | `Decimal` | Yes |
| `best` | `Decimal` | Yes |
| `worst` | `Decimal` | Yes |

Its parts keep these rules, and a value that breaks one fails with the rule's name:

- `best_above_worst`: best > worst
- `value_on_scale`: worst <= value and value <= best

## Example

```jadpo
Rating { value: 4.5 best: 5.0 worst: 1.0 }
```

## Good to know

- `best` must be above `worst`, and `value` between them.
- `==` tells you whether two are the same. `<` and `list.sort_by` don't take it, so sort by one of its parts instead.

## In JSON

An object of its parts, in a request, a response or `json.write`:

```json
{"value":"4.5","best":"5","worst":"1"}
{"value":"8","best":"10","worst":"0"}
{"value":"92","best":"100","worst":"0"}
```

## Details

<details>
<summary>Text form, storage, how it is shown, and operations</summary>

`Rating` is in the group Commerce and logistics, and has been in Jadpo since 0.1.0.

### Text form

It has no single text form, so `text.from` and `text.parse` don't take it.

### How it is stored

It is stored in 3 columns, each named for the field, `_` and its suffix. This is `{"value":"92","best":"100","worst":"0"}`:

| Column | Type | Holds |
|---|---|---|
| `<field>_value` | `numeric` | `92` |
| `<field>_best` | `numeric` | `100` |
| `<field>_worst` | `numeric` | `0` |

### How it is shown to people

`text.format(value, locale:)` shows it to people in their locale.

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `{"value":"4.5","best":"5","worst":"1"}` | `4.5/5` |
| `{"value":"8","best":"10","worst":"0"}` | `8/10` |
| `{"value":"92","best":"100","worst":"0"}` | `92/100` |
| `{"value":"1","best":"5","worst":"1"}` | `1/5` |

### Operations

It also takes `text.format`, `json.read`, `json.write` and `==`. [How every standard type behaves](/docs/every-standard-type-meets-one-contract.md) says how they work.

</details>
