# `InterestRate`

A rate of interest a year and the basis it is quoted on, shown as a lender writes it, `5.5% APR`. The rate may be below 0%, as central banks' have been.

[Money and banking](types.md#money-and-banking); not ordered; since Jadpo 0.1.0.

## Make one

Build one from its fields, `InterestRate { rate: ...  basis: ... }`.

## Fields

| Field | Type |
|---|---|
| `rate` | [`Percentage`](type-percentage.md) |
| `basis` | [`InterestRateBasis`](type-interest-rate-basis.md) |

## Text, JSON and storage

It has no single text form, so `text.from` and `text.parse` don't take it. JSON sends an object of its parts.

| JSON |
|---|
| `{"rate":"5.5%","basis":"apr"}` |
| `{"rate":"4.75%","basis":"aer"}` |
| `{"rate":"-0.5%","basis":"aer"}` |
| `{"rate":"3%","basis":"flat"}` |

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'` |

## 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 has the contract's own operations: `text.format`, `json.read`, `json.write` and `==`. It isn't ordered, so `<` and sorting don't take it. [Every standard type meets one contract](../topics/every-standard-type-meets-one-contract.md) says how they work.
