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

# Variables

> Variables are the named values a domain calculates with. Each is defined by a key, kind, format, optional unit options, and optional default, and carries a value with its unit and provenance when a calculation runs.

A **variable** is a named value within a [domain](https://docs.truemath.ai/concepts/domains.md) — a home price, an
interest rate, a monthly payment. Variables are what [activities](https://docs.truemath.ai/concepts/activities.md)
relate, and what you provide and receive when you run a calculation.

## What a variable has

A variable is **defined** in a domain and takes on a **value** when a calculation runs.

As defined, a variable has:

* **A key** — an identifier, unique within the domain. You reference a variable by its
  key when you provide or solve for it (see [Input formats](https://docs.truemath.ai/concepts/input-formats.md)),
  and the API returns it on each variable.
* **A title and description** — human- and agent-readable labels.
* **A kind and a format** — what the value is, and how it is shown (see below).
* **A default value** — an optional value and unit used when none is provided.
* **Unit options** — an optional list of suggested units for the variable, in order (see below).

When a calculation runs, each variable also has:

* **A value** — the number or table it currently holds, with its **unit** where
  applicable; the unit is part of the value (see
  [Units and precision](https://docs.truemath.ai/concepts/units-and-precision.md)).
* **Provenance** — where that value came from: user-stated, calculated, carried forward,
  or a default. See [Provenance](https://docs.truemath.ai/concepts/provenance.md).

## Kinds and formats

A variable holds one of TrueMath's value types — a [scalar number](https://docs.truemath.ai/math/types/scalar-numbers.md), a [unit number](https://docs.truemath.ai/math/types/unit-numbers.md), or a [table](https://docs.truemath.ai/math/types/tables.md) — and its **kind** says what that value is:

* **`number`** — a plain number, shown with thousands separators. A monetary amount is a number whose unit is a currency (for example `USD`).
* **`percent`** — a rate shown as a percentage.
* **`no_separator`** — a number shown without thousands separators (for example, a year).
* **`duration`, `date`, `datetime`, `time`** — a span of time, a calendar day, a day with a clock time, or a time of day. Each is an ordinary number counting seconds. See [Authoring dates and durations](https://docs.truemath.ai/authoring/dates-and-durations.md).
* **`table`** — a collection of values with named rows and columns.
* **`bar_chart` / `pie_chart`** — a table presented as a chart.

The variable's **format** says how that value is shown, from the vocabulary its kind takes: a number of decimal places for a `number`, `percent`, or `no_separator`, and a [date or duration format token](https://docs.truemath.ai/authoring/dates-and-durations.md#choosing-a-format) for the four time kinds. A format applies to display only. The stored value keeps [full precision](https://docs.truemath.ai/concepts/units-and-precision.md).

## Unit options

A variable can have **unit options**: a list of suggested units, in order.

```json theme={null}
"unit_options": ["yr", "mo"]
```

These are the units an application should offer for the variable. A loan term is usually given in years or months, a dollar amount in `USD`. The order is the author's, and the first unit is the **primary unit**. There is no separate setting for it.

The list is a suggestion, not a restriction. A calculation can use any unit TrueMath recognizes, and [dimensional validation](https://docs.truemath.ai/concepts/units-and-precision.md) is unchanged: `3562 days` is a valid loan term, just not one a form has to offer. This matters most in [natural language](https://docs.truemath.ai/concepts/input-formats.md#natural-language), where people write in whatever unit they are thinking in.

A variable does not need unit options. Without them, the application decides which units to offer.

Only two kinds have unit options: `number` and `no_separator`, whose values are plain numbers that can hold a unit. A `percent` is always a bare decimal, and the four date and duration kinds are always counts of seconds shown through a [format token](https://docs.truemath.ai/authoring/dates-and-durations.md#choosing-a-format), so there is nothing to offer for those.

A [table](https://docs.truemath.ai/authoring/tables.md#configuring-columns) variable has no unit options of its own. Its columns each have their own instead, one list per column, because a table is filled in a column at a time. A [chart](https://docs.truemath.ai/authoring/charts.md) has none: a chart is output, not something a person fills in.

Currency units in the list are also how money is marked. There is no money kind: an amount in dollars is a `number` whose value holds `USD`, and listing `USD` as a unit option is how an application can tell the field is money. See [Reading unit options](https://docs.truemath.ai/api/domains.md#reading-unit-options).

For how values combine across types, see [Combining types](https://docs.truemath.ai/authoring/writing-equations.md#combining-types). For
authoring variables, see [Defining variables](https://docs.truemath.ai/authoring/defining-variables.md).

> [!NOTE]
>
> To list the variables in a published domain, use
> [`GET /v1/domains/:id/variables`](https://docs.truemath.ai/api/domains).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.