marekskopal/orm-decimal

Decimal type from ext-decimal PHP extension mapper for MarekSkopal ORM.

Maintainers

Package info

github.com/marekskopal/orm-decimal

pkg:composer/marekskopal/orm-decimal

Statistics

Installs: 306

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.1.0 2026-03-09 23:31 UTC

This package is auto-updated.

Last update: 2026-03-09 23:32:54 UTC


README

PHP License

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

Installation

composer require marekskopal/orm-decimal

The ext-decimal extension 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's Column attribute with Type::Decimal and registers DecimalMapper as its value handler.
  • DecimalMapper — implements MapperInterface, converting database strings to Decimal\Decimal objects on read (mapToProperty) and back to strings on write (mapToColumn).

License

MIT — see LICENSE.