# `Alternera.Resources.Finance.Convert`
[🔗](https://github.com/10e-ab/alternera-finance/blob/v0.9.0/lib/alternera/resources/finance/convert.ex#L1)

The units of measure's **Convert**: an amount in one unit, in another of
the same base unit. It reads the two units in the caller's tenant, as the
caller, and changes nothing.

It is the Ash action `UnitOfMeasure.convert` (`run/3`), which the REST
API (`GET …/unit_of_measure/convert?amount=2&from=KG&to=G`) and the MCP
tool `run_resource_calculation` run, and the page's Convert button
(`handle_action/4`) runs that same action.

# `convert`

```elixir
@spec convert(Decimal.t(), struct(), struct()) ::
  {:ok, Decimal.t()} | {:error, String.t()}
```

`amount` of `from` in `to`: `{:ok, decimal}`, or `{:error, message}` when
the two have different base units or `to` has a factor of 0. The Unit
converter in the Workbench uses it too.

# `message`

```elixir
@spec message(term()) :: String.t()
```

What an Ash error from a convert action says, for the action's dialog: each error's
own message (`KG and L have different base units`), not the error's
report with its bread crumbs.

# `show`

```elixir
@spec show(Decimal.t()) :: String.t()
```

A decimal as it is: no trailing zeros, no exponent.

# `show_result`

```elixir
@spec show_result(Decimal.t()) :: String.t()
```

A unit conversion's result as the converter shows it: at most
12 significant digits, but every digit before the point,
with no trailing zeros and no exponent. A division by a factor such as
453.59237 (G to LB) runs to Decimal's 28 digits, more than any reader
needs; an amount the reader typed is shown with `show/1`, as it is.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
