Easy way to add decimal functionality to your laravel models

1.0.0 2022-02-26 14:38 UTC

This package is not auto-updated.

Last update: 2022-08-13 17:14:30 UTC


this package use php-decimal for handle decimal. you can see documentation with this link:

you can use php-decimal in your php project, but if you need to have decimal in your model you should have decimal cast in your laravel project. with this project you will have that:)

this package helps you to have Decimal object in your models and do not loose anything in casting and saving in database.


composer require roboticsexpert/laravel-decimal


after installing, go to that model you need have decimal attribute and add that field in cast array like this:

use Roboticsexpert\LaravelDecimal\DecimalCast;

class YourModel extend Model {
    public $cast=[
        'your_field' => DecimalCast::class,


after adding that you can set value to your model like this:

$value = new \Decimal\Decimal('12345.131123123123123');
$model=new YourModel();
... (other stuff)

for getting value it will return Decimal object and you can do anything you want with that:

$model->your_filed // \Decimal\Decimal "12345.131123123123123"

//add 123 to your field

//sub 123 from your field

// check php-decimal package for other methods you can use!