# 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`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.interestprotocol.com/overview/deprecated/sui-tears/collections/coin-decimals.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
