marekskopal / orm-decimal
Decimal type from ext-decimal PHP extension mapper for MarekSkopal ORM.
v1.1.0
2026-03-09 23:31 UTC
Requires
- php: >=8.4
- ext-decimal: *
- marekskopal/orm: ^1.0
- php-decimal/php-decimal: ^1.1.0
Requires (Dev)
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^13.0
- slevomat/coding-standard: ^8.15
README
Decimal\Decimal type mapper for marekskopal/orm, powered by the ext-decimal PHP extension. Handles precise decimal arithmetic without floating-point rounding errors — ideal for monetary values and other exact numeric data.
Requirements
- PHP >= 8.4
ext-decimalPHP extensionmarekskopal/orm^1.0
Installation
composer require marekskopal/orm-decimal
The
ext-decimalextension must be installed separately. See php-decimal.io for installation instructions.
Usage
Apply the #[ColumnDecimal] attribute to a Decimal property on your ORM entity. The precision and scale parameters map directly to the SQL DECIMAL(precision, scale) column type.
use Decimal\Decimal; use MarekSkopal\ORM\Attribute\Entity; use MarekSkopal\ORM\Decimal\Attribute\ColumnDecimal; #[Entity] class Product { #[ColumnDecimal(precision: 8, scale: 2)] public Decimal $price; #[ColumnDecimal(precision: 10, scale: 4, nullable: true)] public ?Decimal $discount; }
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
precision |
int |
yes | Total number of significant digits (must be > 0) |
scale |
int |
yes | Digits after the decimal point (must be < precision) |
name |
string |
no | Override the database column name |
nullable |
bool |
no | Allow null values (default: false) |
How It Works
ColumnDecimal— a PHP attribute that extends the ORM'sColumnattribute withType::Decimaland registersDecimalMapperas its value handler.DecimalMapper— implementsMapperInterface, converting database strings toDecimal\Decimalobjects on read (mapToProperty) and back to strings on write (mapToColumn).
License
MIT — see LICENSE.