The Amount & Currency System
Working with monetary values — Amount objects, cents-as-integers, Currency model, price adapters.
WordPress plugin
Last updated: October 26, 2026
Siren represents every amount as an integer at its currency’s scale. For money that’s hundredths (cents for USD, pence for GBP, and hundredths of a yen for JPY), and for points it’s whole units. This avoids the floating-point precision errors that plague financial software. The Amount model pairs an integer value with a Currency object, and the FloatToIntPriceAdapter handles conversions.
What is the Amount model?
The Amount model (Siren\Commerce\Models\Amount) is a value object that pairs an integer value with its currency.
class Amount
{
protected int $value;
protected Currency $currency;
public function __construct(int $value, Currency $currency)
{
$this->value = $value;
$this->currency = $currency;
}
public function getValue(): int // e.g., 1999 for $19.99
public function getCurrency(): Currency
}
Amount is a value object — it holds the numeric value and its associated currency, nothing more. It has no setters; create a new instance to represent a different amount.
Key Design Decision: Integers, Not Floats
Every amount in Siren is an integer: the shown amount times 10 to the power of the currency’s scale. Every built-in currency has a scale of 2, JPY and KRW included. For USD, 1999 means $19.99. For JPY, 1999 means ¥19.99, which Siren shows as ¥20 because yen shows no decimal places, and a ¥5,000 order is stored as 500000. A currency you create in the admin, or through the REST API with type set to internal, counts whole units (scale 0), so 1999 means 1999 points, and the create route refuses any other scale for it. A custom currency keeps the scale it was stored with. When you build a Currency for points in code, pass a scale of 0 yourself, because the constructor defaults to 2.
The stored integer is what PHP code, adapters, and the record-level REST routes (such as POST /transactions) work with. The /event/sale ingestion route is different: it takes decimal amounts as they appear on the order, such as 5000 for a ¥5,000 order, and converts them for you.
Why integers?
// This is wrong — floating point:
0.1 + 0.2 === 0.3 // false in most languages
// This is correct — integer cents:
10 + 20 === 30 // always true
Floating-point arithmetic produces rounding errors that compound across thousands of transactions. When calculating commissions on affiliate sales, even a fraction-of-a-cent error per transaction becomes real money at scale.
How does Siren represent currencies?
The Currency model (Siren\Commerce\Models\Currency) stores a currency code, display symbol, symbol position, name, scale, the number of decimal places it shows, and whether it’s money or an internal currency such as points or store credit.
class Currency implements DataModel, HasSingleStringIdentity
{
use WithSingleStringIdentity;
protected string $symbol;
protected string $position;
public function __construct(
string $id, // ISO 4217 code: 'USD', 'EUR', 'GBP'
string $symbol, // Display symbol: '$', '€', '£'
string $position = 'before', // 'before' or 'after'
?string $name = null, // 'US Dollar'
int $scale = self::DEFAULT_SCALE, // stored digits after the point, 2 by default
?int $decimalPlaces = null, // digits shown, never more than the scale
string $type = self::TYPE_MONETARY // or self::TYPE_INTERNAL
)
}
| Property | Type | Description |
|---|---|---|
$id | string | ISO 4217 currency code (e.g., 'USD') |
$symbol | string | Display symbol (e.g., '$', '€', 'R$') |
$position | string | Whether symbol appears 'before' or 'after' the number |
$name | ?string | Display name (e.g., 'US Dollar') |
$scale | int | Digits stored after the decimal point. Defaults to 2. |
$decimalPlaces | ?int | Digits shown, never more than the scale. JPY and KRW show 0. |
$type | string | TYPE_MONETARY for money, TYPE_INTERNAL for points or store credit |
Available Currencies
Siren registers 23 currencies out of the box via RegisterCoreCurrencies:
| Code | Symbol | Code | Symbol | Code | Symbol |
|---|---|---|---|---|---|
| USD | $ | EUR | € | GBP | £ |
| JPY | ¥ | CNY | ¥ | AUD | $ |
| CAD | $ | INR | ₹ | BRL | R$ |
| ZAR | R | SGD | $ | MYR | RM |
| THB | ฿ | SEK | kr | CHF | CHF |
| NZD | $ | MXN | $ | HKD | $ |
| NOK | kr | KRW | ₩ | TRY | ₺ |
| RUB | ₽ | PLN | zł |
WooCommerce and Easy Digital Downloads also register the store’s own currency with the store’s symbol, symbol position, and number of decimals, so a store currency the list above lacks, such as DKK, becomes a registered currency. The setting changes how amounts show. They’re still stored at a scale of 2.
Additional currencies can be registered by listening to the CurrencyRegistryInitiated event:
use Siren\Configs\Core\Events\CurrencyRegistryInitiated;
use Siren\Commerce\Models\Currency;
// In your initializer's getListeners():
CurrencyRegistryInitiated::class => MyCustomCurrencyRegistrar::class,
// In the handler:
public function handle(Event $event): void
{
$event->addCurrency('NGN', fn() => new Currency('NGN', '₦'));
}
How do you convert between float prices and integer cents?
FloatToIntPriceAdapter converts between the float prices that e-commerce platforms use and the integers that Siren stores. Without a currency it uses a scale of 2. Pass the currency to convert at that currency’s scale.
class FloatToIntPriceAdapter
{
public function toInt(float $amount, ?Currency $currency = null): int // 19.99 → 1999
public function toFloat(int $amount, ?Currency $currency = null): float // 1999 → 19.99
public function toString(Amount $amount, $decimalSeparator = '.', $thousandsSeparator = ','): string
}
toInt — Platform Price to Siren
$adapter = new FloatToIntPriceAdapter();
// WooCommerce returns floats:
$wcPrice = $order->get_total(); // 49.99
// Convert for Siren:
$cents = $adapter->toInt($wcPrice); // 4999
This is used extensively in order-to-transaction-details adapters. Every line item value, shipping total, tax total, and discount must go through toInt() before entering the transaction details array.
toFloat — Siren to Display
$displayPrice = $adapter->toFloat(4999); // 49.99
toString — Formatted Currency String
$amount = new Amount(4999, new Currency('USD', '$'));
$formatted = $adapter->toString($amount); // "$49.99"
$euroAmount = new Amount(4999, new Currency('EUR', '€', 'after'));
$formatted = $adapter->toString($euroAmount, ',', '.'); // "49,99 €"
The toString method respects the currency’s position property. Symbols marked 'after' follow the number after a space, and others come before it.
Using Amount in Transaction Details
When building the transaction details array for SaleTriggered, every value field must be in integer cents. Here is the pattern from the WooCommerce adapter:
// From OrderToTransactionDetailsAdapter::toArray()
$shippingTotal = $this->priceAdapter->toInt($order->get_shipping_total());
if ($shippingTotal > 0) {
$result[] = [
'name' => 'Shipping',
'description' => 'Shipping Fees',
'type' => 'shipping',
'value' => $shippingTotal, // Integer cents
'quantity' => 1,
'units' => $currency, // e.g., 'USD'
'externalId' => null
];
}
// For line items, value is per-unit:
$total = $this->priceAdapter->toInt($item->get_total());
$result[] = [
'value' => $total / $item->get_quantity(), // Per-unit price in cents
'quantity' => $item->get_quantity(),
// ...
];
The value field in transaction details is the per-unit price, not the line total. The system multiplies value * quantity internally.
Discounts are represented as negative values:
$discount = $this->priceAdapter->toInt($order->get_discount_total());
if ($discount > 0) {
$result[] = [
'type' => 'discount',
'value' => $discount * -1, // Negative value
// ...
];
}
Amount in Incentive Calculations
The incentive system uses Amount to represent commission pools — the total reward to distribute for a conversion.
How does Siren resolve currencies for programs?
This service resolves the correct currency for a program’s incentive calculations:
public function buildCurrency(int $programId): ?Currency
{
$program = $this->programs->find($programId);
$code = $program->getUnits();
if ($code !== '') {
$units = $this->currencyProviderService->getCurrencyFromCode($code);
// Lite doesn't know custom currencies, so it pays no reward.
if ($units === null && !$this->customCurrencies->supported()) {
return null;
}
}
if (!isset($units)) {
$units = $this->currencyProviderService->getDefaultCurrency();
}
return $units;
}
Each program has a units field (e.g., 'USD'). The service resolves this to a Currency object. A program with no currency pays in the default currency. A program naming a currency the site doesn’t know pays in the default currency on Essentials and up, and gets null (no reward) on Lite.
Reward Pool Calculation
Pool calculators return Amount objects:
// StandardRewardPoolCalculationService
$pool = $poolCalculator($binding->getProgramId(), $conversion, $transaction);
return new Amount($pool, $this->currencyProvider->buildCurrency($binding->getProgramId()));
// LeadRewardPoolCalculationService (fixed amount per lead)
$pool = (int) $this->incentiveConfigDatastore->getConfig($programId, 'payoutPerLead', 0);
return new Amount($pool, $this->currencyProvider->buildCurrency($programId));
The $pool value is an integer at the currency’s stored scale: hundredths for money, whole units for a currency you create. The Amount wrapping adds currency context so downstream formatters know how to display it.
How do you access currencies at runtime?
The CurrencyProviderService is the central service for currency operations. Inject it via the interface Siren\Commerce\Interfaces\CurrencyProviderService:
interface CurrencyProviderService
{
public function getCurrencyFromCode(string $currencyCode): ?Currency;
public function resolveCurrency(?string $currencyCode): Currency;
public function getDefaultCurrency(): ?Currency;
public function setCurrency(Currency $currency);
public function getCurrencyIdentifiers(): array; // ['USD', 'EUR', ...]
public function getBuiltInCurrencyIdentifiers(): array;
public function getCurrencies(): array; // [Currency, Currency, ...]
}
The default currency is stored in the config table under group 'commerce', key 'currencyCode', context 'default'. It defaults to 'USD' if not set.
To turn a shown amount into a stored integer and back, use Siren\Commerce\Services\CurrencyAmountService: toStored(), toFloat(), toDecimalString(), format(), and maxStored(), the largest amount a currency accepts. It reads the currency’s scale, so it handles money and whole-unit currencies the same way.
Summary of Conventions
Always store monetary values as integers. Multiply by 100 when ingesting money from platforms, and always use FloatToIntPriceAdapter::toInt() rather than casting manually. The value field in transaction details is per unit, and the system handles the value * quantity multiplication. Discounts should be negative (multiply the amount by -1). Each program can operate in a different currency, so currency is resolved from the program configuration. And Amount is a value object, so create new instances rather than changing existing ones.