---
url: >-
  https://game-engine-io.github.io/enginex-frontend-sdk/reference/api/@getenginex/sdk/functions/toMinorUnits.md
---
[Reference](../../../index.md) / [@getenginex/sdk](../index.md) / toMinorUnits

# toMinorUnits()

> **toMinorUnits**(`value`, `currency`): `number`

Converts the typed or computed value in the main unit (`19.99`, `'19,99'`, `'1.234,56'`)
into minor units (an integer), with no floating-point error: the decimal text is read digit by
digit. With more decimal places than the currency has, it rounds half up over the decimal value
given (`'1.0050'` → `101`). Separators: with `.` and `,` together, the last is the decimal; a single
separator that appears once is the decimal; repeated, it is thousands. A single separator followed by
exactly 3 digits (`'1.000'`, `'1,000'`) is **ambiguous** (a thousand or one?): it throws `RangeError`, except
for 3-decimal currencies, where it is decimal. Pass a `number` or a normalized text (`'1000'`,
`'1.000,00'`); a `number` is never ambiguous. Negatives are rejected: deposit and
withdrawal amounts are never negative.

## Parameters

### value

`string` | `number`

Value in the main unit, as a `number` or text (`'12,50'`, `'1.234,56'`).

### currency

[`CurrencyInfo`](../interfaces/CurrencyInfo.md)

The operator's currency (`config.currency`).

## Returns

`number`

## Example

```ts
toMinorUnits('12,50', currency) // 1250
toMinorUnits(19.99, currency) // 1999 (19.99 * 100 would give 1998.9999999999998)
```

## Throws

Empty, non-numeric, ambiguous, negative, infinite value or above the largest safe integer.
