# Currencies

Source: https://developers.swell.is/frontend-api/currencies

**Swell.js:**

Methods to format money, and handle currency selection and conversion when multi-currency is enabled.

### Format currency

*Returns a formatted string based on store currency settings.*

This method will automatically use the store's base currency settings by default, or the selected currency in a multi-currency setup.

**Format currency**

**swell.js**

```javascript
swell.currency.format(10) // => $10.00
```

Optionally override default currency settings:

**Override default currency settings**

**swell.js**

```javascript
swell.currency.format(10, {
  code: 'EUR',
  locale: 'en-GB',
  decimals: 4, // number of decimal digits
  rate: 0.8874, // conversion rate
  convert: true // set to false to format the amount as-is
}) // => €8.8740
```

### List enabled currencies

*Returns an array of enabled currencies. Result will be empty if multi-currency has not been configured on the store.*

**List enabled currencies**

**swell.js**

```javascript
await swell.currency.list()
```

**Show example result**

**List currency example result**

**swell.js**

```javascript
[
  {
    "code": "USD",
    "rate": 1,
    "name": "US Dollar",
    "symbol": "$",
    "decimals": 2,
    "type": "base"
  },
  {
    "code": "EUR",
    "rate": 0.82542,
    "name": "Euro",
    "symbol": "€",
    "decimals": 2,
    "type": "display"
  },
  {
    "code": "AUD",
    "rate": 1.28934,
    "name": "Australian Dollar",
    "symbol": "A$",
    "decimals": 2,
    "type": "display"
  }
]
```

### Select a currency

*Sets a browser cookie and updates the user's session and cart to the selected currency.*

In a multi-currency setup, call the `select()` method to change settings used by `format()` to render money values.

If a cart exists in the user's session, this method also updates the cart to reflect the user's currency preference.

**Select a currency**

**swell.js**

```javascript
await swell.currency.select('EUR')
```

### Get the selected currency

*Returns the selected currency code. Defaults to the store's base currency.*

**Get the selected currency**

**swell.js**

```javascript
swell.currency.selected() // => USD
```

### Multi-currency formatting

In a multi-currency setup, `format()` uses the options of the selected currency. Each enabled currency has a type, and the type determines whether the amount is converted.

- `base`: the store's base currency. Amounts are formatted without conversion.
- `priced`: a currency with prices entered directly against it. Amounts are formatted without conversion.
- `display`: a currency derived from the base currency. Amounts are multiplied by a conversion rate that is updated daily, then rounded using the currency's rounding settings.

Passing an explicit `rate` converts the amount for any currency type, and `convert: false` formats the amount as-is even for a display currency. An amount is also left unconverted when no rate is available, which is the case for a `code` that isn't one of the store's enabled currencies.

**Multi-currency formatting**

**swell.js**

```javascript
swell.currency.format(10) // => $10.00

await swell.currency.select('EUR')

swell.currency.format(10) // => €8.874
```

See our help center for more details on multi-currency setup.

**GraphQL:**

Methods to format money, and handle currency selection and conversion when multi-currency is enabled.

### List enabled currencies

Returns an array of enabled currencies. The result will be empty if multi-currency has not been configured on the store.

The parameters for this query are `_locale` and `_currency`.

**List enabled currencies**

**GraphQL**

```graphql
query getStoreCurrencies {
  storeSettings(_currency: "USD") {
    store {
      currencies {
        code
        name
        rate
        symbol
        decimals
        priced
        type
      }
    }
  }
}
```
