> For the complete documentation index, see [llms.txt](https://laot7490.gitbook.io/ltbridge/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://laot7490.gitbook.io/ltbridge/utilities/math.md).

# Math

## Math

Number utilities — formatting money, clamping values, interpolation, and rounding.

### Functions

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Clamp</strong></td><td>Clamp a value between min and max.</td><td><a href="#clamp">#clamp</a></td></tr><tr><td><strong>FormatMoney</strong></td><td>Format a number as money with currency symbol.</td><td><a href="#formatmoney">#formatmoney</a></td></tr><tr><td><strong>FormatNumber</strong></td><td>Format a number with thousand separators.</td><td><a href="#formatnumber">#formatnumber</a></td></tr><tr><td><strong>Lerp</strong></td><td>Linear interpolation between two values.</td><td><a href="#lerp">#lerp</a></td></tr><tr><td><strong>MapRange</strong></td><td>Map a value from one range to another.</td><td><a href="#maprange">#maprange</a></td></tr><tr><td><strong>RandomFloat</strong></td><td>Get a random float in range.</td><td><a href="#randomfloat">#randomfloat</a></td></tr><tr><td><strong>Round</strong></td><td>Round a number to given decimal places.</td><td><a href="#round">#round</a></td></tr></tbody></table>

***

## Clamp

Clamp a value between min and max.

{% hint style="info" %}
**Side:** Shared · **Category:** Math · **API:** `LT.Math.Clamp`
{% endhint %}

### Example

```lua
local result = LT.Math.Clamp(1, 1, 1)
```

### Parameters

| Name    | Required | Description |
| ------- | -------- | ----------- |
| `value` | Yes      | number      |
| `min`   | Yes      | number      |
| `max`   | Yes      | number      |

### Returns

* `number`

***

## FormatMoney

Format a number as money with currency symbol.

{% hint style="info" %}
**Side:** Shared · **Category:** Math · **API:** `LT.Math.FormatMoney`
{% endhint %}

### Example

```lua
LT.Math.FormatMoney(1234567) -- "$1,234,567"
LT.Math.FormatMoney(1234567, '€') -- "€1,234,567"
```

### Parameters

| Name     | Required | Description                      |
| -------- | -------- | -------------------------------- |
| `num`    | Yes      | number                           |
| `symbol` | No       | Currency symbol, defaults to "$" |

### Returns

* `string`

***

## FormatNumber

Format a number with thousand separators.

{% hint style="info" %}
**Side:** Shared · **Category:** Math · **API:** `LT.Math.FormatNumber`
{% endhint %}

### Example

```lua
LT.Math.FormatNumber(1234567) -- "1,234,567"
```

### Parameters

| Name  | Required | Description |
| ----- | -------- | ----------- |
| `num` | Yes      | number      |

### Returns

* `string`

***

## Lerp

Linear interpolation between two values.

{% hint style="info" %}
**Side:** Shared · **Category:** Math · **API:** `LT.Math.Lerp`
{% endhint %}

### Example

```lua
local result = LT.Math.Lerp(1, 1, 1)
```

### Parameters

| Name | Required | Description                |
| ---- | -------- | -------------------------- |
| `a`  | Yes      | Start value                |
| `b`  | Yes      | End value                  |
| `t`  | Yes      | Interpolation factor (0-1) |

### Returns

* `number`

***

## MapRange

Map a value from one range to another.

{% hint style="info" %}
**Side:** Shared · **Category:** Math · **API:** `LT.Math.MapRange`
{% endhint %}

### Example

```lua
LT.Math.MapRange(50, 0, 100, 0, 1) -- 0.5
```

### Parameters

| Name     | Required | Description |
| -------- | -------- | ----------- |
| `value`  | Yes      | number      |
| `inMin`  | Yes      | number      |
| `inMax`  | Yes      | number      |
| `outMin` | Yes      | number      |
| `outMax` | Yes      | number      |

### Returns

* `number`

***

## RandomFloat

Get a random float in range.

{% hint style="info" %}
**Side:** Shared · **Category:** Math · **API:** `LT.Math.RandomFloat`
{% endhint %}

### Example

```lua
local result = LT.Math.RandomFloat(1, 1)
```

### Parameters

| Name  | Required | Description |
| ----- | -------- | ----------- |
| `min` | Yes      | number      |
| `max` | Yes      | number      |

### Returns

* `number`

***

## Round

Round a number to given decimal places.

{% hint style="info" %}
**Side:** Shared · **Category:** Math · **API:** `LT.Math.Round`
{% endhint %}

### Example

```lua
local result = LT.Math.Round(1, 1)
```

### Parameters

| Name       | Required | Description   |
| ---------- | -------- | ------------- |
| `num`      | Yes      | number        |
| `decimals` | No       | Defaults to 0 |

### Returns

* `number`
