PHPackages                             au9500/laravel-big-decimal-cast - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. au9500/laravel-big-decimal-cast

ActiveLibrary[Database &amp; ORM](/categories/database)

au9500/laravel-big-decimal-cast
===============================

Custom Brick/Math BigDecimal cast for Laravel Eloquent.

v1.0.0(5mo ago)0101MITPHPPHP ^8.2

Since Nov 30Pushed 5mo agoCompare

[ Source](https://github.com/AU9500/laravel-big-decimal-cast)[ Packagist](https://packagist.org/packages/au9500/laravel-big-decimal-cast)[ RSS](/packages/au9500-laravel-big-decimal-cast/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (5)Used By (0)

📘 Laravel Big Decimal Cast
==========================

[](#-laravel-big-decimal-cast)

A lightweight Laravel package that provides a highly accurate BigDecimal Eloquent Cast based on brick/math. Designed for financial, scientific, or high-precision calculations where standard PHP floats fail.

🚀 Features
----------

[](#-features)

- Casts database values into Brick\\Math\\BigDecimal
- Automatically converts the value back when saving
- Fully configurable precision (scale) and rounding mode
- Zero dependencies besides brick/math and Laravel support
- Auto-discovery support for Laravel
- Allows safe and precise arithmetic operations

📦 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require au9500/laravel-big-decimal-cast

```

For development, you can load the package via a local path repository inside your application composer.json.

🛠 Usage
-------

[](#-usage)

### 1. Add the cast to your Eloquent model

[](#1-add-the-cast-to-your-eloquent-model)

```
use Au9500\LaravelBigDecimalCast\Casts\BigDecimalCast;

class Product extends Model
{
    protected $casts = [
        'price' => BigDecimalCast::class,
    ];
}

```

### 2. Use it like a normal number — but with precision

[](#2-use-it-like-a-normal-number--but-with-precision)

```
$product = Product::find(1);

// BigDecimal instance
$price = $product->price;

// Add numbers with precision
$product->price = $product->price->plus('19.99');

$product->save();

```

⚙️ Configuration
----------------

[](#️-configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag=big-decimal-cast-config

```

This will create:

config/big-decimal-cast.php

```
