---
title: Currency
---

# Currency

<div class="documentation__toc"></div>

## Currency

The `currency` service is a simple class that helps work with money formats. The currency service uses the `streams::currencies` configuration.

## Basic Usage

You can use the currency class by including the `\Anomaly\Streams\Platform\Support\Currency` class.

### format

The `format` function returns the `number` in currency format proceeded by the system configured `currency` symbol.

You may also specify an optional currency code to use specifically. The system configured currency will be used by default.

Lastly you can specify an array of `options` to change configured behavior. Available options are `direction`, `separator`, `decimals`, and `point`.

```php
$currency = app(\Anomaly\Streams\Platform\Support\Currency::class);

$currency->format($number, $currency = null, array $options = [])

// Sum up the "amount" of a collection of entries.
// Assuming "amount" is an integer field type.
echo $currency->format($payments->sum('amount.value'));
// $12,712.93
```

```twig
{{ currency_format(number) }}
{{ currency_format(number, currency) }}
{{ currency_format(number, currency, options) }}

// Sum up the "amount" of a collection of entries.
// Assuming "amount" is an integer field type.
{{ currency_format(payments.sum('amount.value')) }}
// $12,712.93
```

### normalize

The `normalize` function returns the `number` in currency format **without** the system configured `currency` symbol.

You may also specify an optional currency code to use specifically. The system configured currency will be used by default.

Lastly you can specify an array of `options` to change configured behavior. Available options are `direction`, `separator`, `decimals`, and `point`.

```php
$currency = app(\Anomaly\Streams\Platform\Support\Currency::class);

$currency->normalize($number, $currency = null, array $options = [])

// Sum up the "amount" of a collection of entries.
// Assuming "amount" is an integer field type.
echo $currency->normalize($payments->sum('amount.value'));
// 12,712.93
```

```twig
{{ currency_normalize(number) }}
{{ currency_normalize(number, currency) }}
{{ currency_normalize(number, currency, options) }}

// Sum up the "amount" of a collection of entries.
// Assuming "amount" is an integer field type.
{{ currency_normalize(payments.sum('amount.value')) }}
// 12,712.93
```
