# `InterestRate`

A yearly rate of interest, and the basis it is quoted on: `5.5% APR`.

Use it for savings and loan rates. It keeps APR and AER from being confused. For a plain percentage, use [`Percentage`](/docs/types/type-percentage.md).

## Shape

| Field | Type | Required? |
|---|---|---|
| `rate` | [`Percentage`](/docs/types/type-percentage.md) | Yes |
| `basis` | [`InterestRateBasis`](/docs/types/type-interest-rate-basis.md) | Yes |

## Example

```jadpo
InterestRate { rate: 5.5% basis: InterestRateBasis.apr }
```

## Good to know

- The rate can be below 0%, as central banks' have been.
- `==` 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
{"rate":"5.5%","basis":"apr"}
{"rate":"4.75%","basis":"aer"}
{"rate":"-0.5%","basis":"aer"}
```

## Details

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

`InterestRate` is in the group Money and banking, 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 2 columns, each named for the field, `_` and its suffix. This is `{"rate":"-0.5%","basis":"aer"}`:

| Column | Type | Holds |
|---|---|---|
| `<field>_rate` | `numeric` | `-0.005` |
| `<field>_basis` | `text` | `'aer'` |

### How it is shown to people

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

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `{"rate":"5.5%","basis":"apr"}` | `5.5% APR` |
| `{"rate":"4.75%","basis":"aer"}` | `4.75% AER` |
| `{"rate":"-0.5%","basis":"aer"}` | `-0.5% AER` |
| `{"rate":"3%","basis":"flat"}` | `3% flat` |

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