> For the complete documentation index, see [llms.txt](https://docs.interestprotocol.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.interestprotocol.com/overview/deprecated/sui-tears/collections/coin-decimals.md).

# Coin Decimals

It stores information about Coins' decimals to allow protocols to fetch them. The idea is to pass a single argument `CoinDecimals` to functions that require several `sui::coin::CoinMetadata` objects.

## Structs

### <mark style="color:blue;">**Decimals**</mark>

```rust
struct Decimals has store {
    decimals: u8, 
    scalar: u64
}
```

* **decimals -** decimals of a `sui::coin`
* **scalar** - The scalar of a `sui::coin`'s decimals. It is calculated by 10^decimals. E.g. `sui::sui` has a scalar of 1\_000\_000\_000 or 1e9.

### <mark style="color:blue;">**CoinDecimals**</mark>

```rust
struct CoinDecimals has key, store {
    id: UID
}
```

The  Decimals struct is saved in CoinDecimals using dynamic fields.

## Interface

### <mark style="color:blue;">new</mark>

**It creates a new CoinDecimals.**

```rust
public fun new(ctx: &mut TxContext): CoinDecimals
```

* **@return** CoinDecimals.

### <mark style="color:blue;">contains</mark>

**Checks if a coin with type `CoinType` has been added to `self`.**

```rust
public fun contains<CoinType>(self: &CoinDecimals): bool
```

* **@param** self A {CoinDecimals} object.
* **@return** bool. True if the coin's decimals and scalar are in the `self`.

### <mark style="color:blue;">decimals</mark>

**Returns the decimals of a coin with the type `CoinType`.**

```rust
public fun decimals<CoinType>(self: &CoinDecimals): u8
```

* **@param** self A CoinDecimals object.
* **@return** u8. The decimals of the coin.

**Aborts**

* `CoinType` has not been added to the `self`.

### <mark style="color:blue;">scalar</mark>

**Returns the decimals scalar of a coin with type `CoinType`.**

```rust
 public fun scalar<CoinType>(self: &CoinDecimals): u64
```

* **@param** self A {CoinDecimals} object.
* **@return** u64. The decimal's scalar. It is calculated by 10^decimals.

**Aborts**

* `CoinType` has not been added to the `self`.

### <mark style="color:blue;">add</mark>

**Adds the decimals and decimal scalar of a coin with type `CoinType` to `self`.**

```rust
public fun add<CoinType>(self: &mut CoinDecimals, coin_metadata: &CoinMetadata<CoinType>)
```

* **@param** self A CoinDecimals object.
* **@return** coin\_metadata The `sui::coin::CoinMetadata` of a coin with type `CoinType`.
